Afghanistan President Hamid Karzai is escorted by Sergeant of Arms of the Senate Terrance Gainer (left) as he walks to a meeting with U.S. sanators Wednesday on Capitol Hill in Washington. (ASSOCIATED PRESS / Manuel Balce Ceneta)

WASHINGTON (AP) — It’s the same debate, the same numbers and practically the same plan, but the White House is working harder to keep troops in Afghanistan than it did in similar but failed discussions in Iraq in 2011.

Security remains shaky in both war zones, but current and former U.S. officials say the Obama administration cannot afford to lose in Afghanistan after a dozen years of fighting and an ongoing threat by al-Qaida and its extremist Taliban allies. Defeating al-Qaida and bolstering Afghan forces to prevent the terror network’s return there has been a top priority for President Barack Obama since he took office, while ending the war in Iraq was the fulfillment of a campaign promise.

“We’ve made a lot of progress against al-Qaida, but the job is not done,” Doug Lute, the top White House military adviser on Afghanistan, told reporters this week. “The Afghan National Security Forces are a work in progress.”

The U.S. has 66,000 troops in Afghanistan, down from a peak of about 100,000 as recently as 2010. Just how many troops might remain is at the heart of widespread discussion in Washington, where Afghanistan President Hamid Karzai meets with Obama on Friday.

As initially in Iraq, U.S. officials are considering keeping between 3,000 and 15,000 American troops in Afghanistan after 2014. That would not happen, however, if U.S. troops are denied legal immunity from prosecution in Afghanistan — which ultimately is what ended the same negotiations in Iraq.

“We’ve seen this movie so many times,” said Sen. John McCain, the senior Republican on the Senate Armed Services Committee, who remains troubled over the Iraq withdrawal. In an interview Wednesday, he urged the White House to keep more than a few thousand troops in Afghanistan “to make a difference and not just become targets for attacks by a resurgent Taliban.”

Karzai met Wednesday with Senate Republican leader Mitch McConnell and three members of the Foreign Relations and Armed Services committees. Asked what number of U.S. forces he would like to see in the country, Karzai declined to answer and joked that he was told by the “organizer of the Senate” to keep quiet.

“I hope we get back to Afghanistan with what the Afghans expect of me to take back,” Karzai told reporters.

A Pentagon report to Congress in December concluded that only one of 23 Afghan National Army battalions was judged to be capable of operating in the field on its own — and even then needed international security advisers.

Afghanistan was dubbed “Obama’s war” after the president surged troops there in 2009 to chase out extremist militants and eliminate their ability to return. By contrast, Obama as a candidate for president had called Iraq a “dumb war” and made ending it a campaign pledge.

However, the Obama administration negotiated with Baghdad throughout 2011 to keep U.S. troops in Iraq as a sort of insurance policy to block Iran from meddling in Iraq’s Shiite-led government and, in turn, re-ignite the country’s Sunni insurgency. Ultimately, Iraq’s parliament refused to renew an agreement to give legal immunity to thousands of American forces, and the U.S. military left at the end of that year as required under a deadline set in 2008 by the administration of President George W. Bush.

Former Ambassador James F. Jeffrey, a career U.S. diplomat who oversaw the administration’s failed negotiations in Baghdad in 2011, said “of course” Obama wanted to keep troops in Iraq and is trying now to keep them in Afghanistan.

“The numbers are eerily familiar and the missions are eerily familiar,” said Jeffrey, who retired last year from the State Department. “I see him carrying out the same plan in Afghanistan that he tried to carry out in Iraq.”

Jeffrey added: “But this isn’t a war that Obama and the Democratic Party hate, and we haven’t achieved a military victory there. Once you commit these troops to the ground, you are stuck until you get a military victory. We more or less won the ground war in Iraq; we have not won the ground war in Afghanistan.”

A U.S. official in Baghdad, however, recently described a new low in escalating political tensions in Iraq that have prompted violence and protests. Baghdad political analyst Wathiq al-Hasehmi said in an interview this week that the U.S. troop withdrawal was “the biggest mistake ever made by the Americans.”

In a conference call this week with reporters to preview Karzai’s visit, Lute and deputy national security adviser Ben Rhodes said the White House would consider withdrawing all American forces from Afghanistan at the end of 2014 — again following the Iraq model — if they are no longer needed or are not given legal immunities. White House officials also are quick to point to the costs of deploying forces — at least an estimated $1 million per soldier each year in Afghanistan — against competing security concerns elsewhere in the world.

However, that may be a White House negotiating gambit to spook Karzai, who has irritated Washington by accusing U.S. troops of being “occupiers” in Afghanistan when American-led offensives have resulted in civilian deaths. But Karzai also has said he wants the U.S. to continue training and equipping Afghanistan’s army and air force, and help protect its people and regional interests.

At the same time, Karzai wants U.S. forces to stay out of urban areas and villages — raising the question of what mission troops would undertake if they remain. Similarly, American troops stopped securing Iraqi cities in 2009, and morphed into a training-only mission in 2010. By 2011, most soldiers rarely left their secured bases and openly questioned why they were there. Just under 200 active-duty troops are currently in Baghdad, all with diplomatic immunity, to help the U.S. Embassy deliver weapons and equipment to Iraqi security forces.

Republican Rep. Mac Thornberry, the vice chair of the House Armed Service Committee, said the White House might as well withdraw all U.S. forces from Afghanistan next year if it decides to strap the military’s mission by only keeping a few thousand there.

“It’s nearly worse to leave with too small a presence that endangers our people, than to get everybody out,” Thornberry said Wednesday. “If people know you’re not serious about staying there, and standing up for them, then they’ve got to cut deals because the bad guys are staying.

“I worry about the Iraq precedent,” he said, “because we left too soon and we are feeling some of the consequences, and I am afraid we’ll feel more.”