LONDON- The United States applied on Thursday to seize an Iranian tanker in Gibraltar, halting its expected release at the last minute and preventing a possible swap for British-flagged tanker held by Iran.

The Grace 1 oil tanker was seized by Royal Marine commandos in a landing in darkness off the coast of the British overseas territory on July 4.

Gibraltar said the tanker was suspected of selling oil to Syria in breach of European Union sanctions. Two weeks later, Iran's Revolutionary Guards seized the British-flagged Stena Impero in the Gulf on July 19.

Gibraltar was widely expected to release the Grace 1 on Thursday, but just hours before, the U.S. Department of Justice sought to seize it.

"The U.S. Department of Justice has applied to seize the Grace 1 on a number of allegations which are now being considered," the government of Gibraltar said, adding the matter would return to the supreme court of Gibraltar at 1400 GMT on Thursday.

Further details were not immediately released about the grounds for the U.S. Justice Department's application. The U.S. Justice Department was not immediately available for comment.

The Gibraltar Chronicle newspaper, which was first to report the news, said the court's chief justice, Anthony Dudley, made clear that were it not for the U.S. move, "the ship would have sailed".

While both Britain and Iran deny they were planning to swap the vessels for each other, there has been widespread expectation that the Britsh-flagged ship will not be freed until the Iranian tanker is released.

The two seized tankers - one in Gibraltar and one in Iran - are seen as a pawns in the standoff between Iran and the West, with their fate tangled in the diplomatic differences between the EU's big powers and the United States.

European countries including Britain strongly disagreed with Washington's decision last year to abandon an international agreement that guaranteed Iran access to trade in return for curbs to its nuclear programme.

Washington has imposed sanctions on Iran with the aim of halting its oil exports altogether. European countries have lifted sanctions against Iran itself but still have a ban on selling oil to Syria, in place since 2011.

Gibraltar denies that it was ordered to detain the Grace 1, which was carrying up to 2.1 million barrels of oil, but several diplomatic sources have said the United States asked the United Kingdom to seize the vessel.

Britain, which has insisted its Iran policy will not change under new Prime Minister Boris Johnson who took office last month, has repeatedly indicated it wants a compromise over the tanker.

The captain and three officers of the Grace 1 have been released from arrest.

A source in Gibraltar had told Reuters ahead of Thursday's court hearing that the Grace 1 would probably be allowed to leave, stoking speculation about a possible tanker swap with Iran.

Britain has announced plans to join a U.S.-led maritime security mission in the Gulf.

Iranian navy commander Rear Admiral Hossein Khanzadi repeated Iran's longstanding demand that Western navies leave the Gulf, which Iran says should be patrolled only by the countries of the region, ISNA news agency reported on Thursday.

"The enemies of the region, America, England and the Zionist regime and their allies, should know that the time of parading, loitering and putting on a hypocritical show in the Persian Gulf region and the sea of Oman is over,” Khanzadi said, according to ISNA.

"The enemies must leave the region as quickly as possible."

(Reporting by Guy Faulconbridge; editing by Michael Holden) ((guy.faulconbridge@thomsonreuters.com; 07825218698;))