Potter was taking charge of Chelsea for just the second time since replacing the sacked Thomas Tuchel in September.
The former Brighton boss had overseen a 1-1 draw with RB Salzburg in the Champions League and was seconds away from another frustrating result until England midfielder Gallagher rode to the rescue.
Odsonne Edouard had put Palace ahead early on before former Barcelona forward Pierre-Emerick Aubameyang equalised with his first goal for Chelsea late in the first half.
That set the stage for Gallagher to come off the bench and win it for Chelsea deep into stoppage-time, in the process breaking the hearts of the team he played for on loan for the whole of last season.
"It's a very special moment to come on and get the winner. It was written in the stars. Everyone knows how much I loved it at Palace but I'm just buzzing to get my first goal," Gallagher said.
Ratings from Selhurst Park can be seen in the gallery above. To view the next image, just swipe.