Iran released ten U.S. sailors on Wednesday after holding them overnight, bringing a swift end to an incident that had rattled nerves days ahead of the expected implementation of a landmark nuclear accord between Tehran and world powers.

Iran's Islamic Revolutionary Guards Corps (IRGC) said it had freed the sailors after determining they had entered Iranian territorial waters by mistake. The sailors had been detained aboard two U.S. Navy patrol boats in the Gulf on Tuesday.

RELATED: Iran says Saudi Arabia cannot cover 'crime' by cutting ties

"Our technical investigations showed the two U.S. 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 apologized," it added.

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

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.

Some conservatives in both countries, enemies since Iran's 1979 Islamic revolution, have criticized the deal that is due to be implemented in the coming days.

RELATED: Stop Iran rally gathers crowd in Times Square

Iran's armed forces chief, Major General Hassan Firouzabadi, said the incident should demonstrate Iranian strength to "troublemakers" in the U.S. Congress, which has sought to put pressure on Iran after the nuclear deal.

And at a presidential campaign rally in the United States, Republican frontrunner Donald Trump, who accuses President Barack Obama of being weak on foreign policy, described the incident as "an indication of where the hell we're going".

Attributing the boats' incursion into Iranian waters to a navigation error marked a de-escalation in rhetoric. Earlier, the Guards had said the boats were "snooping" in Iranian territory and said Foreign Minister Mohammad Javad Zarif had demanded an apology from Washington.

RELATED: Iran strikes historic nuke deal with U.S. and world powers

The IRGC, the Islamic Republic's praetorian guard, is highly suspicious of U.S. military activity near Iran's borders and many senior officers suspect Washington of pursuing regime change in Tehran.