US President Joe Biden has declared that he plans to end the longest American war and that it is "time for American troops to come home" from Afghanistan.

Mr Biden is looking to close out 20 years of US military involvement there even as critics warn that peace is not assured.

In a White House speech, President Biden set a goal of withdrawing all 2,500 US troops remaining in Afghanistan no later than 11 September, with the final withdrawal beginning on 1 May.

By pulling out without a clear victory, the United States opens itself to criticism that a withdrawal represents a de facto admission of failure.

"I am now the fourth American president to preside over an American troop presence in Afghanistan. Two Republicans. Two Democrats," Mr Biden said.

"I will not pass this responsibility onto a fifth.

"It is time to end America's longest war. It is time for American troops to come home."

The date for withdrawal, 11 September, is a highly symbolic date, coming 20 years to the day of al Qaeda's attacks on the United States that prompted then-president George W Bush to launch the conflict.

The war has cost the lives of 2,400 American service members and consumed an estimated $2 trillion. US troop numbers in Afghanistan peaked at more than 100,000 in 2011.

Meeting NATO officials in Brussels earlier, Secretary of State Antony Blinken said foreign troops under NATO command in Afghanistan will leave the country in coordination with the US withdrawal by 11 September, after Germany said it would match American plans.

Mr Blinken also spoke by phone with Pakistan's army chief and discussed the peace process, according to a statement from the media wing of Pakistan's military.

Afghan President Ashraf Ghani wrote on Twitter that he has spoken with Mr Biden and he respects the US decision.

Mr Ghani added that "we will work with our US partners to ensure a smooth transition" and "we will continue to work with our US/NATO partners in the ongoing peace efforts".

The Democratic president had faced a 1 May withdrawal deadline, set by his Republican predecessor Donald Trump, who tried but failed to pull the troops out before he left office.

Mr Biden's decision will keep troops in Afghanistan past that deadline, but officials suggested troops could fully depart before 11 September.

In a statement NATO said that allies agreed to start the withdrawal of its forces in Afghanistan by 1 May.

NATO's 30 allies said: "Allies have determined that we will start the withdrawal of Resolute Support Mission forces by May 1. We plan to have the withdrawal of all US and Resolute Support Mission forces completed within a few months."

There is a summit planned about Afghanistan starting on 24 April in Istanbul that is due to include the UN and Qatar.

The Taliban, ousted from power in 2001 by US-led forces, said it would not take part in any meetings that would make decisions about Afghanistan until all foreign forces had left the country.

Taliban spokesman Zabihullah Mujahid called on the US to adhere to the deal the group reached with Trump's administration.

"If the agreement is committed to, the remaining problems will also be solved," Mr Mujahid wrote on Twitter.