The comedian walked out on stage to surprise Barlow, the cast from the singer’s musical comedy The Girls - which is based on Calendar Girls - and 130 members of the Women’s Institute (WI).
He had Take That singer Barlow in stitches with his Calendar Girls inspired get-up of nude underwear and jewellery.
Walliams had only some trays of cupcakes to protect his modesty.
The Britain’s Got Talent judge hosted the show at the Eventim Apollo in Hammersmith.
Other stars on the bill included Robbie Williams, Emeli Sande and Britain’s Got Talent winner and magician Lance Corporal Richard Jones.
The event is staged in aid of the Royal Variety Charity, formerly the Entertainment Artistes’ Benevolent Fund, of which the Queen is patron.
The money raised from the show helps those people from the world of entertainment in need of care and assistance.
Barlow’s The Girls opens in London’s West End in 2017.
It is about a group of Yorkshire women who convinced the WI to appear in a nude calendar to raise money for their local hospital.
The story was turned into a film starring Helen Mirren and Julie Walters in 2003.
* The Royal Variety Performance will be broadcast on Tuesday, December 13, at 7.30pm on ITV.