President Barack Obama is confronted with a recent burst of strength by al-Qaida that is chipping away at the remains of Mideast stability, testing his hands-off approach to conflicts in Iraq and Syria at the same time he pushes to keep thousands of U.S. forces in Afghanistan.

Al-Qaida-backed fighters have fought hard against other rebel groups in Syria in a sideshow to the battle to unseat President Bashar Assad. Across the border in Iraq, they have led a surprisingly strong campaign to take two of the cities that U.S. forces suffered heavy losses to secure after their 2003 invasion.

The setbacks highlight the tension between two of Obama’s top foreign policy tenets: to end American involvement in Mideast wars and to eradicate insurgent extremists — specifically al-Qaida. It also raises questions about the future U.S. role in the region if militants overtake American gains made during more than a decade of war.

In Afghanistan, Obama has decided to continue the fight against extremists, as long as Afghan President Hamid Karzai signs off on a joint security agreement. Obama wants to leave as many as 10,000 troops there beyond December, extending what already has become the longest U.S. war. But officials say he would be willing to withdraw completely at the end of this year if the security agreement cannot be finalized.

That would mirror the U.S. exit from Iraq. A spike in sectarian violence followed the abrupt U.S. withdrawal at the end of 2011 after failure to reach a security agreement, leading to the current battle for Ramadi and Fallujah by an al-Qaida affiliate known as the Islamic State of Iraq and the Levant. Iraqi officials said an airstrike in Ramadi killed 25 of the militants Tuesday, but the fighters remained in control of the city.

Marina Ottaway, a senior scholar at the Woodrow Wilson Center in Washington, said the extremists are a spillover from the conflict in Syria and have been bolstered by Obama’s reluctance to arm the more moderate rebels fighting Assad.

“There is no doubt that the U.S. policy helped create a vacuum in which the only effective forces were the radical forces,” Ottaway said Tuesday.

White House officials contend that keeping American troops in Iraq would have done little to stop the current violence.

“There was sectarian conflict … in Iraq when there were 150,000 U.S. troops on the ground there,” White House spokesman Jay Carney said. “So the idea that this would not be happening if there were 10,000 troops in Iraq I think bears scrutiny.”

Army Chief of Staff Gen. Ray Odierno, a former top commander of U.S. forces in Iraq, said al-Qaida and other insurgents are seeking to take advantage of sectarian tensions across much of the Mideast.

“This is not just about Iraq,” Odierno told reporters Tuesday. “It’s something that we have to be cognizant of as we look across the Middle East: What’s going on in Syria, what’s going on in Lebanon, what’s going on inside of Iraq.”

He added, however, that he would not recommend sending U.S. troops back to Iraq — something Iraqi Ambassador Lukman Faily said Baghdad would also oppose. But Faily said Kabul should think twice before rejecting plans for Americans to stay in Afghanistan.

“The abruptness of the U.S. forces departing from Iraq, versus our own requirement to have sovereignty at any cost, was not something beneficial for all parties,” said Faily. “And what we see now is the aftermath of that. …There was no clear day-after scenario.”