The Prince also presented medals to outstanding pupils at Duke Of York's Royal Military School, near Dover.
The first clue students had as to the identity of the guest was when the band started playing the national anthem.
"I didn't believe it, I was so shocked," said 14-year-old Megan Davidson, a drummer with the school's military band.
Sean Dunoo, 11, who was on parade when the Prince walked past, said: "I thought 'Is that Prince Harry?', then I asked my friend next to me and he said 'Probably not' but I said 'Yes, it's him'."
Prince Harry, dressed in his Blues and Royals uniform and peaked cap, was also given a private tour of the school's chapel and met with staff and sixth formers.
The military school was established in 1803 in Chelsea by Frederick, Duke of York to care for the orphans of soldiers.
The Prince met Simon Daglish, an ex-pupil and current governor of the school, when he took part in the first stage of a polar expedition to raise funds for charity Walking With The Wounded, which supports injured ex-servicemen and women.
Prince Harry surprised students at a military school when he made an unannounced parade ground inspection.