Washington - An American student detained in Iran who was freed this month under a prisoner swap said on Thursday he was accused of trying to overthrow the Iranian government and held for nearly a month in solitary confinement.

Matthew Trevithick, who had traveled to Iran to study Farsi, told CNN that interrogators at Iran’s Evin Prison also accused him of having access to millions of dollars and knowledge of secret weapons caches.

In his first television interview since his Jan. 16 release, he described his 41-day ordeal, including how he was captured and his treatment and conditions at the prison.

Asked what he would tell tourists or students considering travel to Iran, he said: “I wouldn’t advise that they go, sadly…. Unfortunately, I don’t think the time is ready for you to go…. I would not encourage people to go to Iran.”

The Massachusetts native had traveled to Iran in September, planning to spend four months at a center affiliated with Tehran University, his family has said.

Trevithick told CNN he was finishing his studies and making plans to go home for the Christmas holidays when he was picked up and driven straight to prison. He said he spent 29 days alone before being moved to a cell with other prisoners.

A jailer asked if he knew Jason Rezaian, the Washington Post journalist who had been held for more than a year in Iran.

“I said of course, the whole world knows Jason Rezaian,” he told CNN. “And he said ‘He’s never leaving and neither are you.’ And that’s when you know it starts to hit you ... I’m a prisoner.”

Trevithick was freed with four other Americans being held, including Rezaian, in a swap that came just as the United States and other world powers implemented a nuclear deal with Iran.

He told his accusers it would be difficult to overthrow the government with the tools he had: “some Farsi textbooks that I’d purchased in Iran, a newspaper, some flashcards and some pens…. They said. ‘Well it’s not our plan, it’s yours’.”

He said interrogators tried to videotape a confession admitting to attempts at overthrowing the Iranian government, but he refused.

The 30-year-old was held for 41 days, 29 in solitary confinement. He said the scariest part of his ordeal was the final two hours before he was released.

“I was kind of violently pulled out of my cell, rushed down to the basement,” he said.

It was there that he was interrogated for a final time.

“They said Matthew, Matt, this is your last chance. Admit why you are here. Admit that you are here to overthrow the government,” he said. “I look right in the camera and I say, ‘I’ve said everything I have to say.’”

Trevithick was taken back to his prison cell, where he was told to collect his belongings and, to his surprise, he was taken to the exit and met by two Swiss diplomats.

“One of them said, ‘We’ll go now. Get in the middle seat,’ and the car took off a 100 miles per hour toward the airport,” he said.

Trevithick arrived back in Boston last week.

Since returning, Trevithick went to eat a hamburger with his mother and is looking forward to watching the new Star Wars movie, according to CNN.

“It’s fantastic to be back,” Trevithick said.