Updated 3:18 p.m. E.T.

Secretary of State John Kerry warned Monday that the threat from militants storming across Iraq could force the U.S. to take military action, even as he pressed the country’s leaders to cede more power to opponents and forge a political solution to the crisis.

“They do pose a threat,” Kerry said of fighters from the militant group Islamic State of Iraq and Greater Syria (ISIS). “They cannot be given safe haven anywhere.

“That’s why, again, I reiterate the President will not be hampered if he deems it necessary if [political reconciliation] is not complete,” Kerry added.

Kerry’s comments came during an unannounced visit to Baghdad, during which he met with the country’s top officials and urged Shi‘ite leaders to cede more power to their rivals as Sunni insurgents plunge the country into chaos.

Kerry had a 90-minute closed-door meeting with Prime Minister Nouri al-Maliki, whom U.S. officials pushed to be more inclusive in his government to bridge the country’s sectarian divide, worsened by years of policymaking that slighted Sunnis and the Kurdish minority in the north. Kerry said afterward that al-Maliki, along with other government officials, had committed to meet a July 1 deadline to build a new power-sharing government.

He also met with top Shi‘ite cleric Ammar al-Hakim and one of Iraq’s most senior Sunnis, parliament speaker Osama al-Nujaifi. “These are difficult times,” he said in the meeting with al-Nujaifi, while reaffirming the Obama Administration’s commitment to stabilizing Iraq’s security. “But the principal concern is for the Iraqi people — for the integrity of the country, its borders, for its sovereignty.”

Kerry spoke about the unrest playing out in Iraq the day before while in Cairo. “This is a critical moment where together we must urge Iraq’s leaders to rise above sectarian motivations and form a government that is united in its determination to meet the needs and speak to the demands of all of their people,” Kerry told reporters.

The Middle East trip comes days after President Barack Obama confirmed the U.S. would send 300 military advisers to assist in the training of the Iraqi military as it attempts to beat back the ferocious assault spearheaded by ISIS extremists. Those troops, Obama said, would not engage in combat missions.

— Additional reporting by Zeke J Miller and Michael Crowley

Contact us at letters@time.com.