US Secretary of State Antony Blinken made a surprise visit to Baghdad on Sunday following a trip to the occupied West Bank earlier in the day.
Iraqi Prime Minister Mohamed Shia al-Sudani met Blinken, the premier's office said, with the two expected to discuss the risks of escalation in Israel's war with Hamas.
Blinken's visit -- which came after a brief stop in Cyprus to discuss a possible maritime aid route to Gaza -- was not announced in advance for security reasons.
Since the start of the Israel-Hamas war, a series of rocket and drone attacks have targeted military bases hosting US forces in Iraq.
"I made very clear that attacks or threats coming from militias that are aligned with Iran are totally unacceptable," Blinken said on Sunday.
"We will take every necessary step to protect our people," he added during a meeting with Sudani.
Washington has accused Iran of having a hand in the attacks which have also targeted American troops in Syria.
Most of the attacks have been claimed by a group known as "Islamic Resistance in Iraq", according to Telegram channels affiliated with Iraqi factions close to Tehran.
Figures released by the Pentagon on Friday showed that between October 17 and November 3 there were 17 attacks in Iraq and 12 in Syria.
Some 2,500 American troops are deployed in Iraq, tasked with advising their Iraqi counterparts in the fight against the Islamic State group.
Sudani condemned the attacks and said that investigations were under way to determine the perpetrators.
Iraq's prime minister has repeatedly called for a ceasefire in the Gaza Strip and has described Israel's military operation in the coastal territory as a "genocide" against the Palestinian people.
Iraq does not recognise Israel as a state and its government is close to Iran, which in turn backs Hamas.
Blinken is engaged in a whirlwind tour of the Middle East, having visited Israel on Friday followed by Jordan on Saturday for talks with King Abdullah II and where he took part in ministerial meetings with five of his Arab counterparts.
On Sunday morning, he travelled to the occupied West Bank to meet Palestinian president Mahmud Abbas, followed by a stop in Cyprus where he met the president and foreign minister.
Blinken says attacks on US troops in Iraq 'totally unacceptable'
US Secretary of State Antony Blinken on Sunday condemned attacks on American troops in Iraq during a surprise visit to Baghdad to discuss the risks of escalation in Israel's war with Hamas.
"I made very clear that attacks or threats coming from militias that are aligned with Iran are totally unacceptable. And we will take every necessary step to protect our people," Blinken said.
His visit comes after a series of attacks targeting bases hosting US troops in Iraq.