The former Take That star took time out from his busy X Factor duties to fly out after Sunday night’s live results show.
He spent Monday meeting members of the British army, navy and airforces as part of an hour-long TV special for ITV, due to air later this year.
Many of the troops and their family and friends posted grateful messages on Twitter alongside touching snaps of Gary posing with personnel.
In one photograph, Gary, 42, is even pictured holding a piece of paper with a message to one of the soldiers’ daughters. "Hello Peyton Daddy misses you loads," read the message, followed by three kisses.
"Gary spent lots of time meeting all the people serving on the frontline, and really enjoyed chatting to them," a source told The Mirror.
“He listened to lots of their stories and they told him how much they missed their families, and he even performed some songs for them.
"Lots of the servicemen and women were saying his visit was a real boost to them.” An ITV spokeswoman said, "We can confirm Gary is doing a one off special to broadcast on ITV later in the year.
The show, set to air in December, will give insight into life on the frontline as well as Gary's special live performances.
Gary, who revealed earlier this month that he is stepping down from the X Factor judging panel to focus on his music career, is set to release his first solo album in 14 years, Since I Saw You Last, on 25 November.
He was recognised for his services to music and charity, including climbing Kilimanjaro for Comic Relief and organising the Children in Need Rocks concert, last month when he was appointed an OBE.