All 10 US Navy sailors detained by Iran after drifting into its territorial waters a day earlier have been freed, the US and Iran said on Wednesday.

The US Navy said the American crew returned safely and there were no indications that they had been harmed while in custody.

The nine men and one woman were being held at an Iranian base on Farsi Island in the Persian Gulf after being detained nearby on Tuesday. The tiny outpost has been used as a base for Revolutionary Guard speedboats as far back as the 1980s.

تکميلي روابط عمومي سپاه: تفنگداران دستگير شده امريکايي، در آب‌هاي بين المللي رها شدند pic.twitter.com/yJskfPW83B — روزنامه شرق (@SharghDaily) January 13, 2016

The sailors left the island at 8:43am GMT aboard the boats that they were detained with, the Navy said. They were picked up by Navy aircraft and other sailors took control of their boats for the return to Bahrain, where the US 5th Fleet is based.

"The Navy will investigate the circumstances that led to the sailors' presence in Iran," the US statement said.

ALSO READ: The personal touch: Zarif, Kerry and 10 US sailors

The Revolutionary Guard's official website published images of the detained sailors before their release showing them sitting on the floor of a room.

"After determining that their entry into Iran's territorial waters was not intentional and their apology, the detained American sailors were released in international waters of the Persian Gulf," a statement posted online by the Guard said on Wednesday.

General Ali Fadavi, the navy chief of Iran's powerful Revolutionary Guard, was quoted earlier on Wednesday by Iranian state TV as saying that an investigation had shown that the Americans entered Iranian territorial waters because of "mechanical problems in their navigation system".

The foreign ministers of both countries, John Kerry and Mohammad Javad Zarif, had been in constant contact, Iranian media said.

The incident came amid heightened tensions with Iran, and only hours before US President Barack Obama gave his final State of the Union address to Congress and the public.

The incident set off a dramatic series of calls and meetings as US officials tried to determine the exact status of the crew and reach out to Iranian leaders.

Iran and the US had no diplomatic relations for more than three decades but tensions have eased after a deal over Iran's nuclear ambitions was signed in July.

Formal implementation of the accord could begin within days, following steps Iran agreed to take to curb its nuclear activities.

The incident came on the heels of an incident in late December when Iran launched a rocket test near US warships and boats passing through the narrow Strait of Hormuz, the route for about a fifth of the world's oil.