Tehran has warned Washington against deploying warships in Iranian territorial waters in the Gulf, after a close encounter earlier in the week between Iranian and US naval ships in the Strait of Hormuz.

Iranian Defence Minister Hossein Dehghan said on Thursday that every US ship that entered Iranian waters would first be warned, but if the intrusion was considered an invasion, there would be a confrontation.

"If an American ship enters Iran's maritime region, it will definitely get a warning. We will monitor them and, if they violate our waters, we will confront them," he said in a statement reported by the Iranian Students' News Agency.

The warning follows an incident on Wednesday when a US warship and Iranian ships faced off near the Strait of Hormuz in the Gulf.

US Navy spokesman Bill Urban said on Thursday that a US Navy patrol boat in the Persian Gulf fired three warning shots after an Iranian vessel approached head on, coming within 200 metres of the US ship.

During Wednesday's incident, the USS Squall "resorted to firing three warning shots from their 50-caliber gun, which caused the Iranian vessel to turn away," he said.

Earlier, a US defence official said that four vessels from Iran's Islamic Revolutionary Guard Corps conducted a "high-speed intercept" of the warship in the Strait of Hormuz.

The official said two of the Iranian vessels came within 300 yards of the USS Nitze in an incident that was "unsafe and unprofessional", underlining the tensions that remain more than a year after Washington and other Western powers reached a landmark nuclear deal with Iran and lifted sanctions.

While the US claims its ship was in international waters, Iran says the vessel was in Iranian waters and therefore violated the country's sovereignty.

A similar incident in January resulted in the arrest of 10 US marines, who were quickly freed after urgent diplomatic negotiations between Iranian Foreign Minister Mohammad Javad Zarif and his US counterpart John Kerry.

In May, a senior Iranian military commander said that Iran would close the strategic Strait of Hormuz, a passageway through which a third of the world's oil is transported, unless the US and its allies stop "threatening" it.

"If the Americans and their regional allies want to pass through the Strait of Hormuz and threaten us, we will not allow any entry," state media quoted Brigadier General Hossein Salami, the deputy commander of the powerful Revolutionary Guard, as saying on Wednesday.

Without elaborating on what he and other leaders would consider a threat, Salami said that "Americans should learn from recent historical truths", most likely referring to the January capture of US sailors who entered Iranian waters in January.

Washington and Tehran have not had diplomatic ties for more than 35 years, but Kerry and Zarif have been in regular contact since 2013 when the international community started hammering out a nuclear deal

with Iran.