Mexico City: A former US Marine, who had been held in Mexican jail for months after arriving at the border from California with guns in his vehicle, was freed on psychological grounds on Friday, a Mexican court said.

Andrew Tahmooressi, 26, an American veteran of the war in Afghanistan who left the US Marines in 2012, had been held in Mexico since his March 31 arrest by Mexican customs agents at the San Isidro border crossing between San Diego and Tijuana.

After agents discovered three guns in his pick-up truck, he was charged with weapons offences and put in prison.

But on Friday, a federal judge in Tijuana freed him so he could be properly treated for the post-traumatic stress disorder (PTSD) he developed after his military service.

“Today, Andrew Paul Tahmooressi was decreed freed, immediately and absolutely,” according to the decision.

After the ruling, the ex-marine was handed over to migration authorities in Mexico so he could be taken to the United States, an official from Tijuana’s home state Baja California told Reuters, speaking on condition of anonymity.

Tahmooressi’s case drew considerable attention, with US

lawmakers taking the unusual step of scheduling a House of Representatives hearing during a congressional recess in the hope of putting pressure on Mexico and on President Barack Obama’s administration to intervene more urgently in the case.

“It is with an overwhelming and humbling feeling of relief that we confirm that Andrew was released today after spending 214 days in Mexican jail,” his family said in a statement.

Tahmooressi was back in the United States and would soon resume treatment for combat related post-traumatic stress disorder, the family added.

Former New Mexico Governor Bill Richardson, who has negotiated on behalf of jailed Americans abroad before, said he visited Tahmooressi at Mexico’s El Hongo Federal Prison and pushed for his release.

“I respect Mexico’s judicial process, and I am pleased that Andrew was released today and will return home to his family,” Richardson said in a statement.

Former Republican presidential candidate John McCain was among those to celebrate Tahmooressi’s release on Twitter.

Supporters said Tahmooressi, who is now in the reserves, entered Mexico accidentally at a poorly marked border crossing after deciding to move to San Diego to get treatment for PTSD.

Mexican authorities have said Tahmooressi did not cross the border by accident and did not declare his weapons.