Palace felt Thiago Silva should have been sent off for a deliberate handball five minutes before he set up Chelsea's equaliser
Substitute Gallagher, who impressed on loan at Palace last season, curled home a superb right-footed effort to snatch victory for Chelsea with his first goal for the club.
Pierre-Emerick Aubameyang also scored his first Chelsea goal on his Premier League return after Odsonne Edouard had poked Palace into an early lead.
However, there was controversy surrounding Aubameyang's goal as it was set up by Thiago Silva, who Palace felt should have been sent off for a deliberate handball which denied Jordan Ayew a possible goalscoring opportunity.
Gallagher, whose impressive form for Palace last season earned him his England debut, was introduced by Potter in the 76th minute for Kai Havertz.
And with the game seemingly petering out for a draw, the 22-year-old midfielder nutmegged Jean-Philippe Mateta before curling a shot into Vicente Guaita's top corner.
However, while Gallagher returned to break Palace hearts, Eagles supporters will likely direct their ire towards the officials following the decision not to send Silva off.
Just after the half-hour mark, the Chelsea defender appeared to deliberately handle the ball after falling to the ground, denying Ayew a possible goalscoring opportunity.
Referee Chris Kavanagh showed the Brazilian a yellow card, which was upheld following a VAR check, much to the dismay of Palace boss Patrick Vieira - who was booked for his protests - and his players.
Palace's sense of injustice deepened when Silva headed James' long ball into the path of Aubameyang, who produced a smart finish on the half-volley to bring Chelsea level.
Because of the postponement of matches following the death of Queen Elizabeth II - for whom a minute's silence was observed before kick-off - and the international break, neither side had played a Premier League game since 3 September.
And while Chelsea looked settled in possession early on, Palace took the lead with their first attack. Edouard pounced on a loose Wesley Fofana pass and found Ayew on the right. The Ghanaian's dipping cross found Edouard, who stretched to poke the ball past Kepa Arrizabalaga.
With their tails up, the home side - who lost Nathaniel Clyne to a serious-looking injury before half-time - immediately pressed for a second as Kepa turned Eberechi Eze's shot from distance around the post with the Palace attacker firing narrowly wide from the resultant corner.
Wilfried Zaha forced a sharp save from Kepa in the second half but Palace were unable to put the Chelsea defence under enough pressure, before Gallagher popped up to rub salt in the home side's wounds and get Potter off the mark as Blues boss.
Aubameyang marked his Premier League return with a well-taken first-half equaliser for Chelsea
-- Courtesy of BBC Sport