TEHRAN, Iran (AP) — All 10 U.S. Navy sailors detained by Iran after drifting into its territorial waters a day earlier have been freed, the U.S. and Iran said Wednesday.

The Navy said the American crewmembers returned safely and there were no indications 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.

The sailors departed the island at 8:43 a.m. GMT aboard the boats 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 U.S. 5th Fleet is based.

“The Navy will investigate the circumstances that led to the sailors’ presence in Iran,” the U.S. statement said.

The Revolutionary Guard’s official website published images of the detained U.S. sailors before their release showing them sitting on the floor of a room. One was a woman with her hair covered by a brown cloth. The pictures also showed what appeared to be their two boats.

“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 Wednesday.

Gen. Ali Fadavi, the Navy chief of Iran’s powerful Revolutionary Guard, was quoted earlier 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.”

U.S. officials also blamed mechanical trouble for the incident.

U.S. officials had said on Tuesday that Tehran assured them the crew and vessels would be returned safely and promptly.

Fadavi said the American boats had shown “unprofessional acts” for 40 minutes before being picked up by Iranian forces after entering the country’s territorial waters. He said Tehran did not consider the U.S. Navy boats violating Iranian territorial waters as “innocent passage.”

The sailors were nonetheless allowed to make contact with the U.S. military based on Iran’s “responsibilities and Islamic mercy” late Tuesday, he said.

Fadavi said Iranian Foreign Minister Mohammed Javad Zarif “had a firm stance” during a telephone conversation with U.S. Secretary of State John Kerry on their presence in Iran’s territorial waters and “said they should not have come and should apologize.”

The Revolutionary Guard’s 200,000-strong force is different from the regular Iranian military and is charged with protecting the ruling system.

The Guard’s naval forces are heavily dependent on fast-moving armed speedboats that can be used in teams to swarm much larger vessels.

Pentagon spokesman Peter Cook told The Associated Press late Tuesday U.S. time that the Riverine boats were moving between Kuwait and Bahrain when the U.S. lost contact with them.

The incident came amid heightened tensions with Iran, and only hours before President Barack Obama gave his final State of the Union address to Congress and the public. It set off a dramatic series of calls and meetings as U.S. officials tried to determine the exact status of the crew and reach out to Iranian leaders.

Kerry, who forged a personal relationship with Zarif through three years of nuclear negotiations, called his Iranian counterpart immediately on learning of the incident, according to a senior U.S. official. Kerry “personally engaged with Zarif on this issue to try to get to this outcome,” the official said.

Kerry learned of the incident around 12:30 p.m. EST as he and Defense Secretary Ash Carter were meeting their Filipino counterparts at the State Department, the official said.

Officials said the sailors were part of Riverine Squadron 1 based in San Diego and were deployed to the U.S. Navy’s 5th Fleet in Bahrain. When the U.S. lost contact with the boats, ships attached to the USS Harry S Truman aircraft carrier strike group began searching the area, along with aircraft flying off the Truman.

The Riverine boats were not part of the carrier strike group, and were on a training mission as they traveled between Kuwait and Bahrain, officials said. The craft are not considered high-tech and don’t contain any sensitive equipment, so there were no concerns about the Iranians gaining access to them, they added.

The officials were not authorized to discuss the sensitive incident publicly so spoke on condition of anonymity.

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

Iran sank a replica of a U.S. aircraft carrier near the strait last February and has said it is testing “suicide drones” that could conduct kamikaze missions on naval ships. It has also challenged foreign cargo ships operating in the Gulf, opening fire on at least two in April and May.

In one of those incidents, Iran temporarily seized a Marshall Islands-flagged cargo ship over what it said was a commercial dispute before releasing it with its crew more than a week later.

Meanwhile, Iran was expected to satisfy the terms of last summer’s nuclear deal in just days. Once the U.N. nuclear agency confirms Iran’s actions to roll back its program, the United States and other Western powers are obliged to suspend wide-ranging oil, trade and financial sanctions on Tehran. Kerry recently said the deal’s implementation was “days away.”

___

Schreck reported from Dubai, United Arab Emirates. Associated Press writers Matthew Lee, Lolita C. Baldor, Bradley Klapper and Richard Lardner in Washington, Jon Gambrell in Dubai and Nasser Karimi in Tehran contributed to this report.