“It’s complicated,” defense secretary Chuck Hagel repeatedly murmured during his three-day visit to Afghanistan this past weekend for a ground’s eye assessment as he prepares to manage the phase-out of American military forces.

Complicated it was. For his host, Afghan president Hamid Karzai, upended all of Washington’s ingrained assumptions about who its Afghan allies are, and even suggested the Americans are now in cahoots with the Taliban.

“I was once a politician,” Hagel redundantlyobserved. No need to be indignant: Karzai’s drumbeat of criticism is part of the normal posturing of practitioners of the trade. “So I can understand the kind of pressures [politicians]—especially leaders of countries—are always under.”

Hagel has it right. An astute political animal, Karzai recognizes that the Afghan public long ago soured on the American military presence. He doesn’t believe his republic needs the foreign troops to survive past next year.

And he calculates that assailing the foreigners—and insinuating they’re conspiring with the Taliban to double-cross him—is his best ticket to shoring up the legitimacy of his regime as it takes charge of facing down the insurgency on its own.

Ironically, many of Karzai’s critics in Afghanistan accuse him of conspiring with the Taliban—or at least trying desperately to court them, since the Taliban continue to rebuff his overtures. And the debatecrystallized around the issue of Bagram prison just as Hagel was arriving in Kabul.

The Americans inflamed Karzai’s bile by abruptly canceling the long-delayed final handover of Bagram prison and its last inmates to the Afghan government, which had at last been scheduled for March 9. But U.S. officials had not retreated from their demand that Karzai commit to keeping behind bars these last prisoners, whom they deem too dangerous for release.

In Washington, President Obama’s conservative critics have pressed him hard. House Armed Services Committee Chairman Howard “Buck” McKeonwarnedObama these detainees—who Karzai says include “many innocent people”—”represent an enduring and continuous threat both to our U.S. forces on the ground in Afghanistan as well as to U.S. national security.”

For Afghans, though, it’s Afghan national forces on the ground, and Afghan national security, that are most immediately at stake. And Karzai insists that Afghans, not foreigners, will decide who must stay in detention. This is a test of Afghan sovereignty, he argues—and if there are suspects against whom even a complaisant Afghan court cannot find convincing evidence, he will not be the Americans’ jailer.

More to the point, Karzai wants the flexibility to use prisoner releases as bargaining chips for dealing with the Taliban. The fiercest enemies of the Taliban in Kabul are already up in arms (perhaps literally, some fear) about Karzai’s supposedly chasing after them to give them a share of power. “One of Karzai’s goals is to have no Taliban in prisons and have them released,” one opposition leadercomplainedto Afghan journalists.

The trick for Karzai is to keep the Kabul coalition together even as he reaches out to the insurgency in hopes of cutting a deal. So far, despite his seeming paranoia about secret dealings, it appears that the Obama administration has been above board with him in deflecting Taliban approaches for bilateral talks, even over hostage releases. The United States has insisted that in any talks it has with the insurgency, Karzai have someone at the table.

To date, the strongly anti-Taliban factions in Afghan politics have been playing by the constitutionally prescribed rules of the game, in part thanks to the foreigners on whose military and financial largess they all have relied. But they, like Karzai, see the inevitable withdrawal of Western troops as a game-changer, particularly if the electoral game for awarding power is rigged.

Karzai and his inner circle have calculated that Afghanistan’s vastly expanded armed forces can hold the line against the insurgency—so long as the international community keeps the funding spigot open to pay army salaries, and keeps the development funding in the pipeline. Ideally sooner, but ultimately later, they believe a frustrated insurgency will either negotiate a settlement with Kabul or run out of steam, having lost the hated alien forces as its prime recruiting tool. (The palace seems to assume Afghans are inured to corruption and kleptocracy.)

In this respect, Karzai’s demand for ousting U.S. special forces from Wardak province, just east of Kabul, makes Afghan political sense if not U.S. military sense. They’re going to be gone sooner or later, and if they’re gone sooner, seemingly at his command, he will show Afghans that he, not the foreigners, is in control of Afghanistan. Karzai, of course, is assuming major risks, since Wardak is the gateway to Kabul.

Amid all the political posturing and positioning as the pace of American and European troop withdrawal accelerates, the United Nations Security Council is hammering out the mandate for the one international presence that is slated to continue in Afghanistan past 2014. The U.N. mission in Afghanistan is due for renewal next week, with responsibility for assisting with the integrity of next year’s national elections, protecting the gains in education and human rights, and reducing illicit drug production,insha’allah.

On so thin a reed do the slender hopes of Afghan civil society for the country’s long-term future ultimately rest.