Iran has released 10 US sailors after holding them overnight, bringing a swift end to an incident that rattled nerves ahead of the expected implementation of a landmark nuclear accord between Tehran and world powers.

Key points:

Iran says US soldiers entered water by mistake due to a faulty navigation system

US says they are still investigating the matter

The sailors were given food and were released unharmed

John Kerry says swift release testament to diplomacy

Iran's Islamic Revolutionary Guard Corps (IRGC) said it freed the sailors after determining they entered Iranian territorial waters by mistake.

The sailors were aboard two US Navy patrol boats in the Gulf on Tuesday.

"Our technical investigations showed the two US Navy boats entered Iranian territorial waters inadvertently," the IRGC said in a statement carried by state television.

"They were released in international waters after they apologised," it added.

US Secretary of State John Kerry thanked Iran for its cooperation in the release of the sailors.

IRGC Rear Admiral Ali Fadavi had earlier said that the two US Navy boats entered Iranian territorial waters due to a broken navigation system.

US Vice President Joe Biden rejected reports that Washington had offered Iran an apology over the incident.

"No, there was no apology, nothing to apologise for ... and there's no looking for any apology," Mr Biden said on CBS's This Morning program.

Diplomacy key to keeping America safe: Kerry

The Pentagon said there were no indications the sailors were harmed while in Iranian custody.

A carefully worded statement did not explain how the sailors and their two riverine command boats ended up being detained by Iran, saying only that "the Navy will investigate the circumstances that led to the sailors' presence in Iran".

The sailors were later taken ashore by US Navy aircraft, while other sailors took charge of the boats and headed towards Bahrain, their original destination.

US Defense Secretary Ash Carter said he was pleased the sailors had been freed and appreciated "the timely way in which this situation was resolved".

Mr Kerry spoke to Iranian Foreign Minister Mohammad Javad Zarif several times as the United States sought to win the release of the sailors, a US official said.

"I think we can all imagine how a similar situation might have played out three or four years ago, and the fact that today this kind of issue can be resolved peacefully and efficiently is a testament to the critical role diplomacy plays in keeping our country safe, secure, and strong," Mr Kerry said.

Mr Zarif said on twitter that he was "happy to see dialogue and respect, not threats and impetuousness, swiftly resolved the sailors episode".

Iranian state television released footage of the arrest, showing the sailors as they knelt down with hands behind their heads and their two vessels being surrounded by several IRGC fast boats.

The video showed weapons and ammunition confiscated from the sailors, who were seen eating food provided by the Iranians. There were also images of American passports being inspected.

The incident raised tensions between Iran and the United States, which, along with other world powers, reached a deal last year under which Iran will curb its nuclear activities in exchange for the lifting of economic sanctions.

A senior US defence official said the circumstances surrounding the incident were still not entirely clear.

"We haven't been able to fully debrief the sailors," the official said, adding the US military hoped to do so within hours. The sailors were headed to a US military facility in Qatar.

"They're going through what always happens in these cases, they'll get a medical evaluation, and there will be a debriefing."