Barack Obama is sending 300 US military advisers to Iraq to help quell its rising insurgency, inching back into a fight he tried to leave behind.
The US president also challenged Iraq's embattled leader to create a more inclusive government or risk his country descending into sectarian civil war.
"The test is before him and other Iraqi leaders as we speak," Mr Obama said of Iraqi prime minister Nouri Maliki, whose political fate appeared increasingly in play as his rivals launched a secretive effort to replace him.
Less than three years after Mr Obama heralded the end of America's war in Iraq, he insisted he was not sending the military back into combat. But , when coupled with previously announced steps, his actions could put about 600 additional US troops in the midst of Iraq's deeply unstable security situation.
Underscoring the volatility was a tenacious fight over Iraq's largest oil refinery north of Baghdad. Iraqi soldiers and helicopter gunships battled Sunni militants for a third day for control of the refinery, the loss of which would be a devastating symbol of the government's powerlessness in the face of a determined uprising hostile to the West.
Despite the deteriorating conditions, Mr Obama held off approving air strikes that the Iraqi government requested to stem the insurgency that has taken over the cities of Mosul and Tikrit and has pressed towards Baghdad.
The president said he could still approve "targeted and precise" strikes if the situation on the ground required it, noting that the US had stepped up intelligence gathering in Iraq to help identify potential targets.
Officials said manned and unmanned US aircraft were now flying over Iraq 24 hours a day on intelligence collection missions. If the US were to proceed with air strikes, officials did not rule out the prospect of hitting targets in Syria, where the militant group pressing through Iraq also has deep ties.
Even as Mr Obama left the door open for a direct military response, he said Iraq's future ultimately rested with its leaders' willingness to embrace a more inclusive political system.
Mr Maliki has long faced criticism from the US for not giving Iraq's Sunni minority a greater role in the Shiite-dominated government. Secretary of state John Kerry is expected to travel to Iraq soon to press its government to share more power.
While US officials have increasingly raised questions privately about whether Mr Maliki can lead his country out of the current crisis, Mr Obama stopped short of calling for the prime minister to step down, saying: "It's not our job to choose Iraq's leaders."
But in what appeared to be a pointed warning to Mr Maliki, he said: "Only leaders that can govern with an inclusive agenda are going to be able to truly bring the Iraqi people together and help them through this crisis."
A leading Sunni tribal chief said Washington's decision to send the military advisers would only make the fighting worse.
Sheikh Ali Hatem al-Suleiman, whose men are involved in the Sunni insurgency led by the al Qaida-inspired Islamic State of Iraq and the Levant (Isis), said the violence would end only if Mr Maliki stepped down.
Both Mr Maliki's Sunni opponents and many of his former Kurdish and Shiite allies have been clamouring to deny the prime minister a third term in office, saying he has excluded them from a narrow decision-making circle. Iraqi political leaders and US officials also have met in recent days to discuss Mr Maliki's future.
Possible candidates were already lining up to replace him, according to Shiite politicians familiar with the secretive efforts. Among them are former vice president Adel Abdul-Mahdi, a French-educated economist who is also a Shiite, and Ayad Allawi, a secular Shiite who served as Iraq's first prime minister after Saddam Hussein's removal.
Also lobbying for the job is Ahmad Chalabi, a Shiite politician who recently joined the Supreme Council and was a favourite by Washington to lead Iraq a decade ago.
The jockeying has been prompted by the lighting gains of Isis, an insurgency fuelled in part by the civil war in neighbouring Syria. The militants have sparked a fresh cycle of sectarian violence in Iraq, which continued when the bullet-riddled bodies of four handcuffed men, presumably Sunnis, were found in a Shiite neighbourhood of Baghdad.
The fight continued for control of the Beiji oil refinery, with Iraq's government desperately seeking to hold off the extremists. The two sides are holding different parts of the refinery, which extends over several square miles of desert.
The 300 Green Beret special operations forces Mr Obama plans to deploy to Iraq will be focused on assessing the state of the Iraqi security forces, which have struggled to hold off the insurgent advances and in some cases have deserted their units.
Initially the deployments will be limited to several teams of about a dozen soldiers apiece, who will operate mainly in Baghdad at various Iraqi military headquarters.
The first wave will also assess the state of the battle with the insurgents and set the stage for the deployment of follow-on military adviser teams. More broadly, the role of the advisers is to gather intelligence and share it with the Iraqi forces, and assess how best to increase the training and equipping of Iraqi security forces in their fight with the rebels.
The military advisers will join up to 275 US forces that Mr Obama previously announced would be positioned in and around Iraq to provide security and support for the US embassy in Baghdad and other American interests.
In the US Congress, reaction to Mr Obama's decisions broke down along party lines with Republicans criticising him but offering wildly different recommendations of what steps to take. Democrats cautiously backed the president.