One soldier was shot and a slum dweller was hit by a stray bullet as Harry met kids in the Brazilian city’s poverty-stricken suburbs known as favelas.

Brave Harry even played street cricket with the youngsters and listened to a choir perform as the gun battles flared less than half a mile away in the Complexo do Alemao.

Rene Silva, one of the young people chosen to accompany the prince, Tweeted about the battle as he showed Harry round.

He said: “The Prince visiting the community on one side and all hell breaking loose on the other... gunfire!!” Another read: “It’s all kicked off!! There are even grenades! There’s been shootings and people are injured...”

Peace forces commander Col Carlos Eduardo Ribeiro, said: “Our soldiers came under fire from possible members of a drugs trafficking gang and responded.

“As well as bullets, home-made bombs were thrown and we responded with stun grenades.”

Harry is in the country – on his first ever solo tour – to mark the Queen’s Diamond Jubilee year.

And the prince, who has also visited Belize, the Bahamas and Jamaica, revealed yesterday he was “humbled” to learn how much his 85-year-old grandmother is loved by people across the Commonwealth.

“I had no idea how much warmth there was towards the Queen,” he said. “To me that’s been very humbling, and I was actually quite choked up seeing the way that they’re celebrating her 60 years.

“She’s thousands of miles away from some of these countries and yet they celebrated her in the way they did, and made me feel so welcome. I couldn’t thank them more.”

Harry, who has also enjoyed beach volleyball, samba dancing and traditional music during his tour, said the Queen had told him: “Enjoy it, I hope you do me proud.”

But the cheeky prince also said he was “funnier” than his gran, saying he got his humour from his grandad, 90-year-old Prince Philip.

“She is very funny, but she gets it from my grandfather,” he said. “They are very funny together. My family is the same as any other when it comes to humour behind closed doors, though I’d like think I was funnier than my grandmother.”