The Taliban has called on President Donald Trump to withdraw US forces from the "quagmire" of Afghanistan, saying nothing has been achieved in 15 years of war except bloodshed and destruction.

In an open letter to the new US president published on one of its official web pages, the Taliban said the US had lost credibility after spending a trillion dollars on a fruitless entanglement.

"So, the responsibility to bring to an end this war also rests on your [Trump's] shoulders," it said.

Afghanistan was invaded by the US in 2001 and has become Washington's longest military intervention since Vietnam.

It has also been the costliest, with more than $100bn spent.

The Taliban justify their ongoing insurgency in the letter, claiming that the group's "Jihad and struggle was legitimate religiously, intellectually, nationally and conforming to all other lawful standards".

So far, Trump has had little to say publicly about Afghanistan, where around 8,400 US troops remain as part of the NATO-led coalition's training mission to support local forces as well as a separate US counterterrorism mission.

Two of Trump's top security appointments - retired Marine Corps General James Mattis as secretary of defense and former General Michael Flynn as national security adviser - both have extensive experience in Afghanistan.

The Taliban, however, warned Trump against relying on the kind of "unrealistic" reports presented to former presidents by their generals, saying: "They would emphasise continuation of war and occupation of Afghanistan because they can have better positions and privileges in war."

Calling the ongoing violence as illegal, ineffective, and aimless, the group claimed "the Afghans, as a nation ravaged by war for 38 long years, sincerely want to bring this war to an end".

OPINION: No consensus in Afghanistan on how to deal with Taliban

"However, they know, despite whatever reasons for previous wars, the principle cause for the ongoing conflict is the presence of foreign occupying forces in our independent country," the letter added.

"You have to realise that the Afghan Muslim nation has risen up against foreign occupation."

The Taliban have made steady inroads against the western-backed government in Kabul since coalition forces ended their main combat mission in 2014, with government forces now in control of only two thirds of the country.

The group has repeatedly urged the US and its allies to leave Afghanistan, ruling out peace talks with the Kabul government while foreign forces remain on Afghan soil.