All 35 crewmen on an anti-piracy ship - from Britain, Estonia, Ukraine and India - were freed Tuesday after winning a prolonged court battle against prison terms for illegally carrying weapons.
The six British crew members gave thumbs-up signs before being driven away from Puzhal prison in the southern Indian city of Chennai by British diplomats.
Fourteen Estonians and three Ukrainians later left the same prison. The 12 Indian members of the crew were freed from another jail, officials said.
It was not immediately known, however, when the foreigners could leave India, even though a high court on Monday overturned the five-year prison sentences passed on them in January 2016.
Indian authorities can still appeal against the latest ruling in the four-year legal rollercoaster.
The men were on the MV Seaman Guard Ohio, operated by a US company to guide ships through pirate-infested Indian Ocean and Red Sea shipping lanes.
The six Britons, all former soldiers, were serving as guards on the vessel when it was intercepted by the Indian coast guard off Tuticorin in Tamil Nadu state in October 2013.
Semi-automatic weapons and thousands of rounds of ammunition were found, and the crew was charged with not having proper paperwork to carry weapons in Indian waters.
US maritime security firm AdvanFort, which owns the Seaman Guard Ohio, repeatedly denied the charges, saying all firearms on board were legally purchased and properly documented.
The crew's case was that the vessel only strayed into Indian waters because they became stranded after running out of fuel.
The 35, except the Ukrainian captain and one Briton, were released on bail in 2014 on condition that they stayed in Chennai.
An Indian court quashed the charges against the crew in July 2014. But the country's Supreme Court overturned that ruling the following year, setting up the trial in 2016 at which they were all jailed.
The families of the crew had lobbied hard for a new hearing, and the Indian government faced pressure from Britain and Estonia over the case.
The Estonian government summoned the Indian ambassador last week to protest over legal delays.
Britain's Foreign Secretary Boris Johnson welcomed the release of the British nationals and said his ministry "has worked tirelessly behind the scenes to reunite these men with their families. The importance the UK government places on their case cannot be understated."
R Arumuga Ram, one of the lawyers for the crew, told AFP the Indian crew members were welcomed by their families outside the prison in the southern city of Tirunelveli.
Harjith Singh, one of the Indians, told Ram that "it was a very painful experience inside the prison."