A Marine veteran jailed for months in Mexico after trying to carry a family heirloom shotgun across the border has been freed.

The attorney for Jon Hammar tweeted Friday night that his client had been released from a detention centre in Matamoros, Mexico, and was "going home". US officials had planned to drive the 27-year-old Hammar across the border at Brownsville, Texas.

Hammar had been jailed since August after he and a friend tried to cross the border with the shotgun, which once belonged to his great-grandfather. Mexico rarely allows foreigners to bring firearms into the country.

Hammar's attorney said Mexican authorities determined there was no intent to commit a crime. Hammar did tours with the Marines in Iraq and Afghanistan. His parents live in South Florida.