The Prince of Wales spoke to troops involved in the mass COVID-19 testing programme in Merthyr Tydfil.
He thanked them for the work they have done as part of Operation Rescript – the military response to coronavirus in the UK.
Brigadier Andrew Dawes, Commander 160th (Welsh) Brigade, said: "It's been an incredibly interesting and sustained period of time for us, to be engaged in these sorts of UK operations.
"We've deployed about 1,200 service personnel, and that's soldiers, sailors and airmen and women, from about 80 different units, if you can believe that, doing all sorts of tasks.
"Behind it all has been a really detailed network of liaison officers, planners, enablers, individuals in Welsh government and NHS Wales just working with our partner organisations to understand what the need is and where service personnel can make the biggest difference."
Brigadier Dawes added: "It was a particular honour today to be asked to attend the Royal visit by the local authority in recognition of what the military have done for the town of Merthyr."
In November, Merthyr had the highest coronavirus infection rate in the country. For every 100,000 people living there, more than 740 had COVID. A third of all tests came back positive.
The Royal Air Force was drafted in to help with the operation of mass testing centres, while soldiers drove ambulances in Caerphilly.
The Ambulance Service found itself stretched to breaking point in December, with 17% of its staff – around 700 people – either sick or self-isolating.
Prince Charles also visited a Cardiff factory that produces camouflage nets and survival kits for the Armed Forces.
Five-and-a-half thousand people in Wales have died from COVID-related illnesses, but fewer than 1% of people are now testing positive.