Iran on Wednesday released 10 U.S. sailors it had detained in the Gulf, moving within hours to head off a potential crisis as it prepares for the lifting of sanctions.
A dramatic series of events started with the sailors -- nine men and a woman -- being taken into custody after their two Navy patrol boats drifted into Iranian territory late on Tuesday.
U.S. and Iranian officials scrambled to defuse the situation, which unfolded as Iran prepares to finally implement a nuclear deal with world powers aimed at ending the Islamic republic's long international isolation.
After informal talks between Washington and Tehran, a statement from the Guards, describing the sailors as Marines, was read out on state television confirming they were free.
"It was determined that the detained American Marines did not enter Iranian waters intentionally. Following their apology, they have been released to international waters in the Gulf," it said.
Still images used in the report showed the sailors sitting calmly on Persian rugs. Iran had earlier said they were being well treated.
Pictures of the U.S. boats, which had green-and-black camouflage patterns, were also shown by state television.
Admiral Ali Fadavi, the naval commander of the Guards, said that an investigation established that "this trespassing was not hostile or for spying purposes" and the sailors had entered Iranian territory "due to a broken navigation system."
U.S. officials had said one or both of the boats had suffered mechanical problems and been taken to Farsi Island, which lies roughly midway between Iran and Saudi Arabia in the Gulf and houses a base of the Guards, which has its own naval units.
Radio contact was lost with the two vessels -- which U.S. officials said were riverine patrol boats under 65 feet (20 meters) in length -- while they were en route from Kuwait to Bahrain.
American officials did not dispute that the vessels appeared to have been in Iranian territorial waters when they were intercepted.
They also said they had received assurances from Tehran that the crews would be allowed to sail onwards come first light.
Washington and Tehran have no diplomatic relations but U.S. Secretary of State John Kerry called Iranian counterpart Foreign Minister Mohammad Javad Zarif to discuss the incident.
The two developed a close working relationship during the nuclear talks, which concluded in July with a deal between Iran and the so-called P5+1 powers of the United States, Britain, China, France, Russia and Germany.
"Mr Zarif had a strong stance and told Mr. Kerry these were our territorial waters and you should apologize," Fadavi said.
The incident came as President Barack Obama gave his last State of the Union address, undermining any attempt to cite closer relations with Tehran as part of his legacy.
As Kerry arrived at the Capitol to hear Obama's speech, he had told a CNN reporter the sailors would be freed "very soon."
"He has a close relationship with foreign minister Zarif and that would be a natural point of contact," White House communications director Jen Psaki told CNN.
"We have been in touch with the Iranians. We have been assured of their safety and that they will be able to move forward on their journey promptly," she said.
The nuclear accord foresees Iran scaling back its activities to put an atomic bomb outside its reach in exchange for relief from crippling international sanctions.
The deal is to be implemented very soon -- Kerry has said "in the coming days" -- but has been criticized by Obama's U.S. opponents as too soft on Tehran.
These rivals seized on the incident in the Gulf to hammer on this point, demanding Obama make a statement and warning Iran must release the sailors.
"Iran is testing the boundaries of this administration's resolve," Republican presidential hopeful Marco Rubio said.
The situation has been further complicated in the New Year by an angry breakdown in relations between Iran and U.S. ally Saudi Arabia, inflaming regional tensions.
Iran's Guards often take a tough approach to perceived and real territorial violations in what it considers the "Persian Gulf".
Relations with Washington were strained by claims last month that Iran fired missiles close to a US aircraft carrier in the Gulf.
Last year, Iranian patrol boats seized the Maersk Tigris, a cargo ship sailing under the Marshall Islands flag, which meant it was under U.S. protection.
And in March 2007, Iranian patrols captured 15 British Royal Navy and Royal Marines personnel, interrogated them and held them for 13 days before releasing them.