WASHINGTON — What is going on with President Hamid Karzai? The world’s only superpower, leading a coalition of some 50 nations, is willing to stay on in his country after a war that has already lasted a dozen years and cost the United States more than $600 billion and more than 2,000 fatalities — and yet the Afghan president keeps throwing up roadblocks.

The latest insult is his decision to hold off on signing a bilateral security agreement, the legal basis for American forces to remain in his country past 2014, on the grounds that his successor should have that prerogative next year. Mr. Karzai has also thrown in new demands — just when we thought the security agreement was a done deal. For one, he now seems to believe he can compel the United States to release all Afghan detainees in the prison camp at Guantánamo Bay.

Certainly, part of Mr. Karzai’s attitude comes from the umbrage he has taken at various Americans, especially in recent years. Some United States officials did make mistakes in their handling of the complex Afghan leader, lecturing him in public too stridently about matters such as Afghan government corruption. There can be little doubt, though, that Mr. Karzai’s own peevishness and ingratitude have played a large role.

In addition, Mr. Karzai believes, accurately perhaps, that the talks over the bilateral security agreement provide him with his last remaining leverage with Washington. He is wrong in thinking that Afghanistan remains a center of geopolitics, the location of a modern-day “great game” like the 19th-century competition between Britain and Russia, or the 1980s Cold War struggle pitting the Soviet Union against the United States and others. But Mr. Karzai is right that we are concerned enough about Afghanistan’s future to wish to maintain a presence even after NATO’s combat mission expires in just 13 months. He also rightly perceives that the United States wants to keep a vigilant eye on extremist groups in tribal regions of northwest Pakistan.