Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

The United States could take pre-emptive military action if it gets sufficient warning that Iran or its proxy forces are planning further strikes on U.S. interests in the Middle East, Defense Secretary Mark Esper said Thursday.

"We're prepared to do what is necessary to defend our personnel and our interests and our partners in the region," Esper told reporters at the Pentagon, citing a series of violent attacks on U.S. personnel and facilities in Iraq in recent months by Iran-supported militia groups.

The United States has "indications" that more Iranian provocations may be in the offing, Esper suggested without providing details.

"If that happens, then we will act and by the way, if we get word of attacks or some type indication, we will take preemptive action as well to protect American forces, to protect American lives," he added.

His comments came after thousands of pro-Iran protesters stormed the U.S. Embassy compound in Baghdad on Tuesday, with some making it as far as the main reception area before failing to gain access to the main building.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

The Joint Operation Command said protesters had burned and broken doors to the reception room at the diplomatic building, which sits on a vast 100-acre site along the Tigris River. It is the United States' biggest embassy.

The protesters were demonstrating against deadly U.S. airstrikes Sunday on weapons depots in Iraq and Syria that the United States said were linked to an Iran-backed Shiite militia group, Kataeb Hezbollah. At least 25 fighters were killed in the strikes.

Also known as the Hezbollah Brigades in Iraq, Kataeb Hezbollah is separate from the Lebanese militant group Hezbollah. It operates under the umbrella of Iranian state-sanctioned militias, known collectively as the Popular Mobilization Forces.

Within hours of the attack on the embassy, President Donald Trump accused Iran of orchestrating the violence. He threatened to retaliate against Iran but said later he did not want war.

Around 750 U.S. troops from the 504th Parachute Infantry Regiment of the 82nd Airborne Division were deployed to the region Tuesday.

In a separate interview with NBC News' Andrea Mitchell on Thursday, Esper said those forces had been sent as "a prudent, precautionary measure to ensure the safety and security of folks not just at the embassy in Baghdad, but in Iraq writ large and frankly the region."

He said they would remain "for as long as is necessary to ensure that mission is accomplished."

Describing the initial response to the protests by the Iraqi security forces as "slow," he said they needed to remain there.

"It is the sovereign responsibility of the Iraqi government to defend not just our embassy but all other embassies in that country," he said.

He added that United States has a full range of capabilities to hit back at Iran, whether on the military side, further economic sanctions or diplomatic action.

Speaking alongside Esper at the Pentagon, Army Gen. Mark Milley, chairman of the Joint Chiefs of Staff, said the United States has enough forces at the embassy to defend it.

"We are very confident that the integrity of that embassy is strong, and it is highly unlikely to be physically overrun by anyone," he said. "There is sufficient combat power there, air and ground, that anyone who attempts to overrun that will run into a buzz saw."