It is a bitter indictment of an army in trouble. It was written by the American soldier Bowe Bergdahl in his last email to his parents sent just before he walked off his base in eastern Afghanistan on 30 June 2009.

Within hours, he was picked by the Taliban who held him for five years until his exchange for five senior Taliban leaders held in the US prison at Guantanamo Bay.

“The US army is the biggest joke the world has to laugh at,” wrote Sergeant Bergdahl in an email later published by Rolling Stone magazine. “It is the army of liars, backstabbers, fools, and bullies. The few good SGTs [sergeants] are getting out as soon as they can, and they are telling us privates to do the same.”

Download the new Independent Premium app Sharing the full story, not just the headlines

Sgt Bergdahl had joined the army when it was short of soldiers to send to Afghanistan as part of the “surge” in the number of combat brigades there. With too few men, it had started to issue “waivers” to recruits facing felony charges or drugs problems who previously would have been turned down for the army. For Sgt Bergdahl, a crack shot, well-educated and with a romantic vision of what professional soldiering involved, disillusionment set in fast.

His company was understrength and demoralised. He complained that three good sergeants had been forced to move to another company and “one of the biggest shit bags is being put in charge of the team”. The commander of his battalion was a “conceited old fool” and other officers were as bad: “In the US army you are cut down for being honest... but if you are a conceited brown-nosing shit bag you will be allowed to do whatever you want, and you will be handed your higher rank.”

Sgt Bergdahl had taken seriously the counter-insurgency strategy supposedly aimed at winning the “hearts and minds” of Afghans. Instead, he found that US soldiers regarded Afghans with aggressive contempt: “I am sorry for everything here. These people need help, yet what they get is the most conceited country in the world telling them that they are nothing and that they are stupid, that they have no idea how to live.”

He spoke of seeing an Afghan child run over by an American heavy-armoured truck, an event which his parents believe may have led him to leave his base. His father responded to his last message with an email in which the subject line was titled: “Obey Your Conscience.”

The life stories of the six men – five Afghans and one American – exchanged this weekend shows how quickly the mood of armies in Afghanistan can switch from full confidence in victory to frustration and defeat. In the summer of 2001 the Taliban rightly believed they were close to taking over the whole of Afghanistan as their enemies were penned into the mountains of the north-east.

But 9/11 changed all that and by November the Americans were cock-a-hoop that they had won an easy success. Eight years later Sgt Bergdahl’s reasons for going Awol illustrate how far Afghanistan turned into a demoralising and unwinnable war for the US.

The Taliban had also seen hopes of victory turn sour in a much shorter period. Mullah Mohammed Fazl, also known as Mullah Fazel Mazloom, was the leader of 10,000 Taliban fighters held responsible for massacres of Hazara and Tajiks in northern Afghanistan.

Daily coronavirus briefing No hype, just the advice and analysis you need Enter your email address Continue Continue Please enter an email address Email address is invalid Fill out this field Email address is invalid Email already exists. Log in to update your newsletter preferences Register with your social account or click here to log in I would like to receive morning headlines Monday - Friday plus breaking news alerts by email Update newsletter preferences

He surrendered to the opposition Northern Alliance in 2001. With him was the governor of Balkh province, Mullah Norullah Noori. They were taken to the battleship USS Bataan and then to Guantanamo.

Ever since exploratory talks started between the US and the Taliban, the first demand of the latter was for these two men to be released. Other prisoners include Khirullah Said Wali Khairkhwa who was a founding member of the Taliban in 1994. In these early days after the fall of the Taliban, an over-confident US saw no reason why former Taliban leaders should be conciliated. Among those senior Taliban security official reported to have vainly reached out to the Americans are the two remaining detainees.

Who could have imagined at the end of 2001 that 13 years later the US would be exchanging prisoners with the Taliban? For the US, getting back their only prisoner detaches them further from Afghanistan, the handover of the five leaders is a sign of their legitimacy and strength.