Outgoing Afghan President Hamid Karzai used his farewell speech to take one last swipe at the United States, capping an often testy relationship with an accusation that America has never wanted peace in Afghanistan.

Mr Karzai, the only president Afghanistan had had since the US-led invasion in 2001, said Washington had wanted war in Afghanistan “because of its own interests”. His relationship with the US has grown increasingly fragile in recent years, but the diplomatic US-Afghan relationship may be reset on Monday when President-elect Ashraf Ghani Ahmadzai will be sworn in.

The US has spent more than $100bn (£61bn) on aid in Afghanistan since 2001 to train and equip the country’s security forces, to pave crumbling dirt roads, to upgrade hospitals and to build schools. But Mr Karzai thanked a slew of other countries for their help – India, Japan, China, Iran, Turkey, Saudi Arabia, South Korea and Germany – without mentioning the US. The speech portrayed the White House and the military leaders of neighbouring Pakistan as backing perpetual war.

“If America and Pakistan really want it, peace will come to Afghanistan,” he said. “War in Afghanistan is based on the aims of foreigners. The war in Afghanistan is to the benefit of foreigners. But Afghans on both sides are the sacrificial lambs and victims.”

More than 2,200 US personnel have died in Afghanistan?, with nearly 20,000 wounded.

The United Nations says 8,000 Afghan civilians have been killed in the conflict over the past five years. For years Mr Karzai has railed against US military strikes for the civilian casualties that some of them cause – although the UN has said insurgents are to blame for the overwhelming majority of casualties.

In his final year in office, Mr Karzai refused to sign a security agreement with the US that would set the legal framework to allow about 10,000 American military advisers and trainers to stay in the country next year. Mr Ghani has said he will sign it.

Mr Karzai’s relationship with President Barack Obama is seen as weak, though US Secretary of State John Kerry appears to have a rapport with the outgoing Afghan President. Dozens of telephone calls made by Mr Kerry to the two top Afghan presidential candidates helped bring about a political deal signed on Sunday for a unity government. Mr Ghani was announced by the election commission as winner of a June run-off election plagued by allegation of widespread vote fraud. His opponent, Abdullah Abdullah, will fill the newly created role of government chief executive.

Samehullah Samem, a member of parliament from the western province of Farah, said Mr Karzai had earned respect among Afghans during his decade-long rule, but that he should be more careful with his words toward an ally. He noted that the Afghan economy is faltering and added: “We are completely dependent on the international community. We need the support of the international community, especially the United States of America. Afghanistan still hasn’t reached a point where it can defend itself or have a self-sufficient economy.”

US military and intelligence operatives helped transport Mr Karzai around the region in late 2001, shortly after the 9/11 attacks in New York and Washington. That US connection helped pave his way to the presidency.

Mr Ghani’s entrance is more conventional. A former finance minister, he worked at the World Bank and earned a PhD from New York’s Columbia University. The long election season ended with the country’s election commission giving him 55 per cent of the run-off vote.

The 13-year war against the Taliban has now largely been turned over to his Afghan security forces and casualties among Afghan soldiers has risen significantly this year.