Family and friends of a Hingham man who is on his way home after being detained for 40 days in Iran said Sunday they’re relieved that he’s been released.

Officials haven’t said why Matthew Trevithick, 30, was taken into custody.

He was released Saturday independently of a prisoner exchange between the U.S. and Iran that saw four American prisoners discharged.

"I don’t think I’ve ever met anyone who exudes as much energy, enthusiasm and curiosity," said Andrew Bacevich, professor emeritus of international relations and history at Boston University, where Trevithick was his student.

Bacevich said he was "immensely gratified" to learn of Trevithick’s release.

"I only hope that his ordeal won’t compromise any of the qualities that make him the special person that he is," Bacevich said.

In a statement, the Trevithick’s family said:

Matthew Trevithick is happy to be back in Massachusetts after his ordeal in Tehran’s Evin Prison. He is doing well, spending time with his family and catching up on Boston sports?.

Trevithick’s Web site said he coached rowing teams in Iraq and Afghanistan while working abroad. That work included time at the American University of Afghanistan and the American University of Iraq.

It was in Iraq that Trevithick met rowing coach Bruce Smith, who was conducting a rowing camp for the Iraqi national rowing team. The two hit it off and collaborated on a project to set up a rowing camp at Lake Dukan in northern Iraq.

"He’s an optimistic and tremendous fellow, and we’re so happy about the work everyone did to secure his release," said Smith, executive director of Community Rowing Inc., in Brighton.

Robin Wright, a joint fellow at the Wilson Center and the U.S. Institute of Peace in Washington, described Trevithick as a "winsome, sweet and intelligent man."

Trevithick was Wright’s research assistant at the Wilson Center in 2009, and the two have remained friends, she said.

"Whenever he came back to the U.S. we saw each other and he came by to schmooze," Wright said.

Trevithick was wrapping up a four-month language program at an institute associated with Tehran University when he was detained, his family said in a statement.

"We’re overjoyed that he’s out and coming home soon," said Trevithick’s mother, Amelia Newcomb. "We couldn’t be happier."

Trevithick’s release coincided with the announcement that Iran has satisfied its obligations under a nuclear deal with world powers.

(Copyright (c) 2016 Sunbeam Television. The Associated Press contributed to this report. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed.)

Join our Newsletter for the latest news right to your inbox