On Friday, the United States attorney’s office in Delaware said it had taken the “exceedingly rare” step of dropping the charges. “We have not hesitated to do so when the facts and law support such a decision,” a statement said.

In an interview last week, Mr. Lopez’s voice broke as he described his prison ordeal. “Nobody deserves to get dragged through what I got dragged through, along with my family,” he said. “It’s sad that when someone does something with righteous intentions and gets treated by the government this way.”

Finding Internet Adversaries

By his own admission, Mr. Lopez knew almost nothing about the Islamic State before 2014. Athletic and fun-loving, he had managed an Italian restaurant for years before becoming a car salesman. He became addicted to painkillers for a while, but he kicked the habit and has been off drugs for several years, he said. “Toby is your regular guy,” said Mary Roloff, who is married to Mr. Lopez’s half brother, Edward.

At first, Mr. Lopez said, he started insulting people who praised the Islamic State on Twitter. Then he decided to learn more about his social media adversaries. He picked up a few Islamic terms online and began to engage the terrorist group’s supporters, even quoting the Quran to counter them. He found the anonymity of the Internet intoxicating. As he put it, nobody knew he was “little Toby, the car salesman from Delaware.”

On Google, Mr. Lopez discovered that one man who had engaged him on Twitter, calling himself @shishaniomar, seemed to be Omar al-Shishani, or Omar the Chechen, the nom de guerre of the military commander of the Islamic State. Soon the two were regularly chatting on Skype. By early November 2014, he had left his job, agreeing with his boss that his online life had become a distraction.

The man who claimed to be the Islamic State commander regaled him with tales of battle, grumbled about condescending Arab bosses and called Mr. Lopez “brother.” The man confided that he did not believe that Islam condoned the taking of women and children as slaves. Soon he asked Mr. Lopez to raise ransom to free hundreds of members of the Yazidi religious minority held hostage by the Islamic State.