IT TOOK a while, but Afghanistan has at last got a new president. After a four-month stand-off during which his rival, Abdullah Abdullah, accused him of stealing the election, Ashraf Ghani, a Pushtun technocrat with a notable temper, was inaugurated on September 29th. As part of the settlement, Dr Abdullah comes into the government in the newly created position of chief executive (in effect, prime minister). It remains unclear how the new arrangement will work; what is certain is that the stand-off damaged the economy, threatened to reopen ethnic divisions and, most dangerous of all, allowed the Taliban and other insurgents to regroup.

If the country is secure, the rest will follow

Security matters above all else: without it, Afghanistan cannot prosper. That is why the new government’s long-delayed signing of a bilateral security agreement (BSA) with America the day after Mr Ghani’s inauguration is so important. A “status-of-forces” agreement with NATO quickly followed it. They come not a moment too soon. The agreements provide the legal basis for Western troops to stay on in Afghanistan after they cease combat operations at the end of the year.

The BSA should have been signed by the outgoing president, Hamid Karzai, last December. But to the horror of most Afghans, Mr Karzai refused at the last moment to put pen to paper. Even without a functioning government in Kabul and with the threat of abandonment by the West a possibility, the country’s security forces have been performing with courage and effectiveness. But fatalities have been running at a rate of about 100 a week, as high as at any time during the 12-year war.

However welcome the BSA, its scope has been constrained, perhaps fatally, by Barack Obama. The president’s military advisers wanted him to commit an enduring force of about 15,000. As well as training and advising the army and police it would provide military assistance, in particular the air power Afghan soldiers have become used to when fighting alongside their NATO partners. That means close air support, aerial surveillance, air transport for special forces and medical evacuation. The generals wanted this force to stay until the Afghans were able to provide these things for themselves.

But rather than heed the advice, in May Mr Obama decided on a force of just 9,800 Americans at the beginning of 2015, falling to half that a year later before being fully withdrawn by the end of 2016. Worse, the “assist” part of the mission now looks as though it will be negligible. Fighter jets, transports and helicopters at the vast Bagram air base near Kabul will not fly to help Afghan forces. A big effort to train and equip the Afghan air force has begun far too late. It will be four years before it can fill the void.

Understandably, Mr Obama wants to put no more Americans in harm’s way and to boast on leaving office that he has brought all the troops home. But this threatens to be a strategic blunder. Mr Obama’s rush to get out of Iraq in 2011 contributed substantially to the conditions that have forced America to start fighting there again. Mr Obama had the excuse that the Iraqis failed to sign a status-of-forces agreement. He does not have that excuse in Afghanistan.

Engaged in another Middle East conflict partly because of his own neglect, Mr Obama is prepared to use American air power in support of an only partially reconstructed Iraqi government, yet refuses similar help to Afghan forces trained and funded by America who are fighting a similar enemy. Unless he wants history to repeat itself, he needs to change his mind about the nature and the duration of the military support America and the West gives Afghanistan.