After missing two gilt-edged opportunities in the EFL Cup final against Liverpool at the weekend, it was some redemption for Gallagher, who bailed a sub-par Chelsea side out against Championship opposition.
Youngster Mateo Joseph scored his first professional goal after a mix-up at the back by the hosts to put Leeds ahead early on, and he also levelled the tie up again after goals from Nicolas Jackson and Mykhaylo Mudryk had turned the game around.
The late strike which sealed Chelsea's 3-2 win will see the Blues meet Leicester City at Stamford Bridge in the quarter-finals, in what will be a repeat of the 2021 FA Cup final, where the Foxes came out on top.
After suffering a sixth straight domestic cup final loss at the weekend against Liverpool in the EFL Cup at Wembley, Chelsea set about continuing their fight to reach another one.
All the stats pointed towards them doing so too, considering they had won six in a row at home to Leeds at home, and had progressed past the fifth round on 13 of the last 15 occasions.
Leeds have been in superb form though, having yet to taste defeat in 2024, and in the midst of a nine-game winning run in the Championship which has brought them back into the title picture.
Despite resting the likes of Wilfried Gnonto and Crysencio Summerville, and being without Georginio Rutter through injury, Daniel Farke's men hit the ground running early, and should have taken the lead when Daniel James outpaced and outmuscled Alfie Gilchrist, before sending a lob over Robert Sanchez wide of the target.
From the resulting goal kick though, the opening goal arrived, as Axel Disasi's calamitous pass out from the back was latched upon, before Jaidon Anthony found Joseph in the centre, and he fired past a bewildered Sanchez.
Chelsea looked extremely nervy in the opening quarter of an hour, conceding possession often with wayward pot shots all they had to show for their early efforts.
However, one clever move which saw Moises Caicedo thread Jackson in down the right led to the equaliser, as the Chelsea front man saw his effort squirm through the legs of Illan Meslier to level proceedings on 15 minutes.
The hosts were then dominant for the rest of the opening period, as Mudryk and Noni Madueke both found room on the left-hand side but failed to beat Meslier merely five minutes apart.
Mudryk kept his head up though and his first goal of 2024 put Chelsea ahead soon after, latching onto Raheem Sterling's pull back to fire a first-time effort out of Meslier's reach to turn the tie on its head.
Leeds threatened very little in the latter stages of first half, but Anthony's effort shortly before the interval saw many around Stamford Bridge hold their breath as it fizzed wide of the far post.
It was Anthony who played a pivotal part in Leeds' equaliser though, as his pinpoint delivery was missed by Trevoh Chalobah, and found Joseph at the back post, and the youngster sent it back from where it came beyond Sanchez and into the back of the Chelsea net to make it 2-2 on the hour mark.
After Chalobah missed another cross from the opposite flank, Joseph could have been on for a third goal had he anticipated the chance, but the opportunity evaded him and the ball bounced off his chest.
As both sides started to send on more of their regular starters who had begun the evening on the bench, Chelsea then took more of the initiative, but after Levi Colwill was unable to gather after some penalty-area pinball, the tie looked destined for extra time.
That was until Gallagher stepped up with just seconds left of the 90, and after missing when through on goal on Sunday, this time the midfielder was able to beat Meslier who was closing him down and hand Mauricio Pochettino's side the win.
Leeds could not fashion a clear chance in four minutes of additional time, as Chelsea progressed to the quarter-finals of a cup competition once again.
It marks a second straight season where Leeds have gone out at this stage, after losing to Fulham last season in the fifth round, and their 21-year wait for an FA Cup quarter-final appearance goes on.