The Script were due to be on stage but when they pulled out due to "serious family illness" Gary decided to step in. He tweeted to say he'd happily do the gig if Blackpool Council agreed to donate some money to Children In Need.
Speaking to BBC News, Gary said: "When I saw the news that they had lost The Script I thought I am going to see if I can do this. When the council said they would make a donation for BBC Children In Need, I decided I'm there."
Donning an "I love BPL" jumper and joined on staged by the Children In Need mascot, Pudsey, Gary put on a good show for fans, who were also treated to sets by Eliza Doolittle and Madness.
The town's council said they were very grateful to Gary, while the X Factor judge added: "I went there on holiday as a kid and it is a very fond place for me."
Gary is back on our TV screens this weekend as he once again takes his seat on the X Factor judging panel alongside Sharon Osbourne, Nicole Scherzinger and Louis Walsh. Catch all the action tonight and tomorrow from 8pm on ITV.