The future King - who wore desert fatigues, helmet and goggles for the helicopter journey to Camp Bastion, northwest of Lashkar Gah in Helmand Province - said the two-day trip was intended to show his gratitude.
"I just wanted to come and say thank you, well done," said the 61-year-old royal, who also praised the "incredible work" done by the men.
"People never understand enough, I don't think, the extraordinary role played by our Armed Forces," he said.
"Not just in the purely military terms, but in all the wonderful things they are doing – aid to the civil power, puting things back together again, starting water supplies, building schools."
The Prince, who is commander in chief of ten regiments, ate with the men in the camp's canteen and slept in an army regulation bed.
He visited patrol base Pimon in Nad-e-Ali and flew in an RAF Chinook to an Afghan National Army camp close to the base.
Charles ended his visit by attending a memorial service, where he laid a poppy wreath in tribute to the 276 soldiers killed in the conflict. Among the dead was a personal friend of his, Lt Col Rupert Thorneloe of the Welsh Guards.