Image copyright AP Image caption Pitts was wounded by shrapnel but eventually made a complete recovery

US President Barack Obama has awarded America's highest military decoration to a soldier who single-handedly fended off a Taliban attack after his comrades were killed or relocated.

Former Staff Sgt Ryan Pitts, 28, is the ninth living veteran of Afghanistan or Iraq to receive the Medal of Honor.

In July 2008 he was manning an observation post that came under attack.

Though wounded, he held off the enemy with grenades and a machine gun.

"In Ryan Pitts you see the humility and the loyalty that define America's men and women in uniform," Mr Obama said at the White House ceremony on Monday. "Of this medal, he says, 'It's not mine alone. It belongs to everybody who was there that day because we did it together.'"

On 13 July 2008, 48 US soldiers including Mr Pitts were setting up a small base in Wanat, Afghanistan.

Mr Pitts and eight other US soldiers were manning a tiny outpost just outside the base, which Mr Obama described as "an elevated patch of boulders and sandbags".

Image copyright EPA Image caption Obama injected a bit of levity into the otherwise solemn ceremony, joking about Pitts' wedding anniversary

'One American'

In the pre-dawn darkness, as many as 200 insurgents attacked with machine guns, mortars and rocket-propelled grenades, and almost immediately Mr Pitts and his team were all wounded.

As the insurgent fighters pressed the attack on his position, Mr Pitts returned fire with grenades and a machine gun, though he was bleeding heavily from shrapnel wounds in the arm and both legs.

After pulling the pins in the grenades, he held onto them for several seconds before throwing them, to ensure they would explode before the enemy fighters could hurl them back at him.

Believing he was about to die, Mr Pitts helped direct US air strikes to reinforce the defenders, ultimately driving the insurgents back.

Mr Pitts was evacuated about an hour after the attack began.

"That little post was on the verge of falling, giving the enemy a perch to devastate the base below,'' Mr Obama said. "Against that onslaught, one American held the line."

In the end, nine American troops were killed in the battle.

"Valour was everywhere that day, and the real heroes are the nine men who made the ultimate sacrifice so the rest of us could return home," Mr Pitts said. "It is their names - not mine - that I want people to know."

Mr Pitts joined the army in 2003 at the age of 17, and trained as an airborne soldier. He deployed twice to Afghanistan and left the army in 2009 after making a full recovery from his injuries.

He now lives in New Hampshire with his wife and one-year-old son, and works in the software industry.