“Without having the documents,” Kirk Heilbrun, a Drexel University psychologist, wrote in his March 2 evaluation, “I would have concluded that his account of this entire series of events sounded both grandiose and delusional. Having reviewed these documents, however, I would not describe his account as delusional.”

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.