President Obama answers a question during a joint news conference with Afghan President Ashraf Ghani at the White House on Tuesday. (Win McNamee/Getty Images)

For a president committed to ending two of America’s longest wars, it has been a rough few days.

First, on Tuesday, President Obama said he would freeze U.S. troop withdrawals in Afghanistan, acknowledging that Afghan forces still lack the firepower and training to hold off the Taliban.

Then on Wednesday, the Pentagon said it had begun dropping bombs in support of a stalled Iraqi offensive in Tikrit, edging the United States deeper into Iraq’s largely sectarian war.

The decisions highlight a tension at the heart of Obama’s wartime presidency between a pragmatic need to limit the chaos in the two battle-scarred countries and the president’s strongly held desire to get the United States out of its longest wars.

“I am not an ideologue,” Obama has often said, as a way of explaining his approach.

But as the end of Obama’s presidency draws closer, his pragmatism is increasingly colliding with his strongly held belief that U.S. military power will never be able to fix the problems in Iraq and Afghanistan. Without a clear end date, senior White House officials warn that the U.S. role in the wars will go on forever.

“When you have these wars that don’t end on battleships with surrender ceremonies, you have to define an end at some point,” said Ben Rhodes, a deputy national security adviser to the president. “In places like Afghanistan, Yemen and Somalia there’s not going to be an end where everything is stable and there’s no violence and bad guys.”

For this week, at least, Obama’s pragmatism trumped his deep convictions.

The combat and surveillance sorties in Tikrit effectively put the U.S. military in the middle of a messy civil war that Obama thought he had ended when he ordered the withdrawal of the last U.S. ground troops in late 2011.

U.S. warplanes will be flying missions in support of about 20,000 Shiite-militia fighters, some of whom are backed by Iran, and 4,000 Iraqi army troops. The Iraqi fighters are trying to dislodge less than 1,000 Islamic State insurgents holed up in fortified fighting positions and surrounded by rings of buried bombs.

One goal of the U.S. intervention is to help the Iraqis build and sustain momentum as they prepare for a bigger battle in Mosul, Iraq’s second-largest city, later this year. U.S. officials had hoped the attack on Mosul could begin as early as next month, though that now seems unlikely.

The U.S. bombs also could cut into the Iraqis’ dependence on Iranian combat advisers who are moving with the Iraqi troops. The Iranians, eager to counter U.S. influence in the region, have sought to minimize the U.S. contribution to the war effort. A senior Obama administration official described the shadowy competition as a “struggle between the United States and Iran for strategic influence and lasting influence” in Iraq.

The U.S. airstrikes, if successful in breaking the bloody stalemate, would make clear to Iraqi Prime Minister Haider al-Abadi and his commanders that they need U.S. military power to defeat Sunni extremists. “We can use the Iraqis’ failure in Tikrit to show what happens if you stiff-arm the U.S. in favor of Iran,” said Stephen Biddle, a frequent adviser to the Pentagon and a professor at George Washington University. “The message is that if you really want a better partner, stick with us and not the Iranians.”

The airstrikes on behalf of Shiite militia forces, though, carry risk. The offensive into Tikrit could further alienate Iraqi Sunnis, some of whom have welcomed the Islamic State insurgents as an alternative to the Shiite-dominated government in Baghdad. The support of Iraq’s minority Sunnis is essential to the Islamic State’s defeat.

In Afghanistan, Obama froze U.S. troop levels at 9,800 through the end of this year, amid worries that Afghan army and police deaths had spiked to unsustainable levels.

The extra 5,000 troops will allow the United States to keep open bases in Kandahar and Jalalabad, where the Taliban remains strong. U.S. forces based near the two cities will advise the Afghan troops and call in U.S. airstrikes to help fend off Taliban assaults. Central Intelligence Agency drones will continue secret counterterrorism strikes from the two bases.

But even as Obama announced the troop freeze, he reiterated his determination to withdraw all U.S. military forces by the end of his presidency and consolidate remaining American military and civilian personnel at the U.S. Embassy in Kabul. The limits reflect Obama’s core belief that U.S. military power can keep a lid on unrest in places such as Iraq and Afghanistan but can’t end the wars or compel a political settlement.

“The president has always been flexible within the broad parameters he’s given to his commanders,” Rhodes said. “Revisiting the 2016 deadline would be a more profound decision.”

The additional 5,000 U.S. troops could help the Afghan forces avoid a serious collapse this coming fight season. As Afghan forces and the country’s newly elected unity government grow stronger, the hope is that the Taliban will feel greater pressure to negotiate a peace deal.

Another possibility is that Obama’s split-the-difference approach, which mixes a pragmatic desire for stability with a determination to leave, could simply prolong the fighting. When U.S. forces depart Afghanistan for good in January 2017, it’s possible that Congress will scale back the $4.1 billion that the United States spends annually to keep 352,000 Afghan troops in the field. For the Taliban, the certainty of U.S. troop withdrawals and the potential loss in funding offer a powerful incentive to put off any negotiated peace for at least a year.

The net result is that the United States could spend tens of billions to keep an extra 5,000 soldiers in the country without significantly changing the fundamentals of the fight. This, Biddle said, illuminates another tenet of war to which Obama definitely does not subscribe.

“The attempt to be reasonable when waging war often leaves you worse off,” Biddle said. “Splitting the difference often means you are just throwing good money after bad.”