Dozens of people stormed the compound of the U.S. Embassy in Iraq on Tuesday in response to U.S. airstrikes that killed dozens of fighters from an Iran-backed militia group.

Guards inside the embassy in Baghdad's heavily fortified Green Zone used tear gas to prevent demonstrators from moving toward the main buildings inside the compound, an Iraqi security source told NBC News on condition of anonymity.

The United States is sending about 750 soldiers to the Middle East after thousands of people stormed the compound of the U.S. Embassy in Baghdad, Defense Secretary Mark Esper said Tuesday night.

Esper said President Donald Trump ordered the deployment, which will come from an infantry battalion of the 82nd Airborne Division, based at Fort Bragg, North Carolina, More personnel are on standby to deploy if they're needed, he said.

"This deployment is an appropriate and precautionary action taken in response to increased threat levels against U.S. personnel and facilities, such as we witnessed in Baghdad today," Esper said in a statement. "The United States will protect our people and interests anywhere they are found around the world."

U.S. fighter jets on Sunday bombed weapons depots in Iraq and Syria that the United States said were linked with a group called Kataeb Hezbollah, which it blames for attacks on bases of the U.S.-led coalition fighting the Islamic State in recent months.

At least 25 militia fighters were killed in the airstrikes. A large crowd of supporters gathered Tuesday after funerals for some of the dead and marched on the embassy, chanting "Down, Down USA!" while hurling water bottles and smashing security cameras, according to The Associated Press.

An AP reporter saw flames rising from inside the compound and at least three U.S. soldiers on the roof of the main building inside the embassy.

Download the NBC News app for breaking news and politics

Live bullets and tear gas injured at least 62 demonstrators, according to the Popular Mobilization Forces, an umbrella group for the militias recognized by the Iraqi government. NBC News couldn't independently verify the claim.

Protesters attack the entrance of the U.S. Embassy in Baghdad on Dec. 31, 2019. Ahmed Jalil / EPA

There were about 6,000 protesters at the height of the demonstrations, a U.S. official said, made up mostly of Kataib Hezbollah members.

The embassy was on lockdown by evening, but U.S. personnel weren't being evacuated, according to a U.S. official with knowledge of the situation. The official said discussions were underway about next steps should an evacuation be necessary.

Trump, who tweeted that he expected protection from Iraq's security forces, accused Iran of having orchestrated the attack, saying the government "will be held fully responsible." He doubled down later Tuesday, saying Iran would "pay a very BIG PRICE. This is not a Warning, it is a Threat." His press secretary, Stephanie Grisham, said the president would choose "how and when we respond to their escalation."

The United States plans to ramp up security around the embassy, deploying about 100 Marines, a defense official said. Additional security was being provided by AH-64 Apache helicopters from an air weapons team.

Half of the extra Marines landed at the U.S. Embassy in Baghdad on two Osprey aircraft, while the other half were en route to the embassy.

Democrats said the attack was the latest example of the failure of the Trump administration's policy in the region.

"It's hard to overstate what a total failure Trump's Iran policy has been," Ben Rhodes, a top national security aide to President Barack Obama, wrote on Twitter. "Nuclear program resumed. Regional provocations escalated. US isolated."

Sen. Chris Murphy, D-Conn., a member of the Foreign Relations Committee, said the attacks were a reminder of how "catastrophic" the year has been for U.S. interests in the Middle East, and he tweeted a long list of problems in the region.

"Really hard to overstate how badly Trump has bungled things in the Middle East," Murphy wrote. "One of the only good things going — anti-Iran street protests in Iraq — have now morphed into anti-U.S. protests thanks to Trump's mishandling of Iran policy."

Secretary of State Mike Pompeo spoke to Iraqi Prime Minister Adil Abdul-Mahdi and President Barham Salih separately by phone on Tuesday and told them that "the United States will protect and defend its people, who are there to support a sovereign and independent Iraq," the State Department said in a statement.

"Both Abdul-Mahdi and Salih assured the Secretary that they took seriously their responsibility for and would guarantee the safety and security of U.S. personnel and property," the statement said.

Matthew Tueller, the U.S. ambassador to Iraq, was out of the country, two U.S. officials with knowledge of the situation said.

Abdul-Mahdi issued a statement urging people to leave the U.S. Embassy, warning that "any aggressive behavior against foreign embassies" would be "strictly stopped by security forces" and punished.

The clashes follow anti-government protests in recent months in which hundreds of people have been killed, according to protest groups, most of them by Iraqi security forces. The mass uprisings prompted the resignation last month of Abdul-Mahdi, who remains prime minister in a caretaker capacity.

The United States blames Kataeb Hezbollah for 11 attacks on bases used by the U.S.-led coalition over the past two months. The latest came on Friday, when a rocket attack killed a U.S. contractor and injured four U.S. service members.

The U.S. airstrikes have been met with an angry reaction from both Iran and Iraq.

The United States has about 5,000 personnel in Iraq to train and assist government troops in the fight against ISIS. But the Iraqi government is also allied with a powerful network of militia groups, many of which are backed by or linked to Tehran.

Tehran called the U.S. airstrikes "terrorism," and Iraq called them a "violation" of its sovereignty. The militia has vowed to respond.

CORRECTION (Dec. 31, 2019, 10:31 a.m.): An earlier version of this article misidentified the White House press secretary. She is Stephanie Grisham, not Graham.