US President Donald Trump says he is prepared to take military action to stop Iran from getting a nuclear bomb but left open whether he would back the use of force to protect Gulf oil supplies.

Worries about a confrontation between Iran and the US have mounted since attacks last week on two oil tankers near the strategic Strait of Hormuz shipping lane at the entrance to the Gulf.

Washington blamed long-time foe Iran for the incidents but Tehran denies responsibility.

However the attacks, and similar ones in May, have further soured relations that have plummeted since Trump pulled the US out of a landmark international nuclear deal with Iran in May 2018.

In an interview with Time magazine, Trump, striking a different tone from some Republican lawmakers who have urged a military approach to Iran, said last week’s tanker attacks in the Gulf of Oman had only a “very minor” impact so far.

Trump was asked if he would consider military action to prevent Iran from obtaining nuclear weapons or to ensure the free flow of oil through the Gulf.

“I would certainly go over nuclear weapons and I would keep the other a question mark,” he replied.

The nuclear deal with Iran, which was reached in 2015 during Barack Obama’s presidency, aimed to head off any pathway to an Iranian nuclear bomb.

Trump says the agreement failed to address Iran’s missile program or punish it for waging proxy wars in Middle East countries.

Tehran has decried the toughening of US sanctions and urged other signatories to take action to save the nuclear pact or see Iran turn its back on the deal.

US Secretary of State Mike Pompeo said the United States will maintain its pressure campaign on Iran and continue to deter aggression in the region but does not want the conflict with Tehran to escalate.

“We have been engaged in many messages, even this moment right here, communicating to Iran that we are there to deter aggression,” Pompeo told reporters on Tuesday.

“President Trump does not want war and we will continue to communicate that message while doing the things that are necessary to protect American interests in the region.”

As tension with Iran rises, uncertainty about leadership of the Pentagon grew on Tuesday with the news that acting Defense Secretary Patrick Shanahan had withdrawn from consideration to head the US military.

USA Today has reported the FBI had been examining a nine-year-old domestic dispute involving Shanahan and his then-wife.