Prince Harry has been praised as an account of him intervening in a homophobic attack on a gay solider has come to light.

The account was published in gay soldier Lance Corporal James Wharton’s new book Out in the Army, in which he writes that Prince Harry stopped the homophobic attack, during which soldiers from another regiment said they were going to “batter” him.

Prince Harry, a tank commander at the time, was approached by Wharton who was tearful, and told him that he thought he was going to be “murdered by the infantry”.

He wrote: “I told him [Prince Harry], ‘I think I’m going to be murdered by the infantry.’ I climbed into the turret and talked Harry through exactly what had happened. He had a complete look of bewilderment on his face.

“I couldn’t stop the tears from welling up in my eyes. He said, ‘Right I’m going to sort this shit out once and for all.’”

He continued that Harry approached the group without hesitating, and that upon his return he said the situation was “sorted”.

“I will always be grateful to Harry,” Wharton continued. “I will never forget what happened. Until he went over and dealt with everything I was on track for a battering.”

Since the story came to light, Prince Harry, described as Wharton as one of his “greatest protectors”, has been praised by Stonewall, as well as Tory MP Bob Stewart and Shadow Defence Secretary Jim Murphy.

Wharton, who served in Iraq, became the first gay man to appear on the cover of Soldier magazine in 2009. In 2010, he and his partner had the Household Cavalry’s first civil partnership.

Prince Harry previously said he might try relationships with men if he “changes his mind” about women, while on a night out with his girlfriend.

In November 2012 Prince Harry and his brother, Prince William, wrote a letter supporting the Terrence Higgins Trust in its campaign against HIV.

Earlier in 2012 Harry came under fire for using the word “queer”, but was defended by Peter Tatchell, who pointed out that Harry has made a video diary in which he kisses and licks the face of another male soldier.