The US president, Barack Obama, has told his Afghan counterpart Hamid Karzai that he is preparing a contingency plan to withdraw all US troops, as a post-2014 security pact remains unsigned.

The message, delivered on Tuesday, however did not rule out making a deal on a post-2014 mission with the next Kabul government.

Obama told Karzai by telephone that the Pentagon had little option but to draw up a contingency plan for a full withdrawal because the Afghan leader had refused to sign a Bilateral Security Agreement with Washington.

"Specifically, President Obama has asked the Pentagon to ensure that it has adequate plans in place to accomplish an orderly withdrawal by the end of the year," the White House was quoted as saying by Reuters.

The US has been pushing for legal immunity for its soldiers and contractors, a point resisted by Karzai.

In case of no deal, the US has indicated that it will go for a "zero option", as it did in Iraq, leaving Afghan forces to battle the Taliban on their own.

The US wants to keep up to 10,000 troops in the country to train and mentor the Afghan national security forces and go after the remnants of al-Qaeda.

Staking out a new position, the White House statement said "we will leave open the possibility of concluding a BSA (bilateral security agreement) later this year. However, the longer we go without a BSA, the more challenging it will be to plan and execute any US mission."

And the longer both countries go without a security deal, "the more likely it will be that any post-2014 US mission will be smaller in scale and ambition," the statement said.

Chuck Hagel, the US secretary of defence, said planning for what the "zero option" was a prudent step given that Karzai had made clear he is unlikely to sign the security deal.

"The United States will consult closely with NATO allies and ISAF partners in the months ahead, and I look forward to discussing our planning with defence ministers in Brussels this week," he said as he left for Brussels.

This comes a day after the bodies of 21 Afghan soldiers killed in Kunar, in the worst Taliban attack on the national army in four years, were returned to their families following a rare public ceremony.