City trailed 2-0 at half-time after two breakaway goals from Lois Openda stunned the Etihad Stadium.
Haaland pulled a goal back shortly after the restart with an emphatic finish before Foden levelled with a clever low strike.
And the comeback was complete with three minutes remaining when Alvarez smashed in a loose ball from close range.
The draw means we will top the group irrespective of the result of the final game away to Red Star Belgrade and will be at home for the second leg of our last-16 tie.
The visitors had conceded 13 goals in their previous two visits to the Etihad, but with qualification for the last-16 also secured, they had nothing to lose as they tried to usurp City at the top of Group G.
Xavi Simons, who had scored in his previous two Champions League away games, fired an early warning with a curling effort just wide of Stefan Ortega Moreno’s far post.
And their bright start led to the opening goal when Openda escaped the marking of Manuel Akanji to dash onto a long ball before neatly finishing past the German keeper.
The City winger received lengthy treatment midway through the first half after a stray knee caught him on the head following a strong tackle.
Leipzig reacted quickest when the game restarted and doubled their lead in the 33rd minute. Openda this time wriggling away from a challenge from Dias before cutting inside Gvardiol and lashing in his second.
Again City were close to a quick reply when Lewis laid a pass into the feet of Haaland but his fierce shot went over the bar while his header on the stroke of half-time was saved at the far post by Janis Blaswich.
And we pulled a goal back when Haaland beat the offside trap to run onto Foden’s throughball before firing low past Blaswich.
The visitors dropped deeper as City dominated possession and Ake went close to an equaliser with a flicked header just off-target from Alvarez’s free-kick.
A second finally arrived in the 70th minute when Foden collected Gvardiol’s pass on the half-turn and slid a shot through the legs of Nicolas Seiwald and into the bottom corner.
RB Leipzig went close to reclaiming the lead with Benjamin Sesko stinging the palms of Ortega Moreno while Fabio Carvalho had a goal ruled out for offside.
But there was to be one more goal in the game as Doku and Foden worked the ball to Alvarez and he steadied himself before smashing the ball past the wrongfooted Blaswich.
LEIPZIG XI: Blaswich, Simakan, Klostermann, Lukeba, Raum, Haidara (Carvalho 74), Seiwald, Schlager (Kampl 88), Simons (Poulsen 74), Forsberg (Baumgartner 59), Openda (Sesko 59)
Subs: Gulacsi, Lenz, Heinrichs
PLAYER OF THE MATCH
Foden was involved in all three City goals as we turned the tie on its head.
The former Academy player took up a more central role alongside Lewis with Bernardo playing on the right wing.
After a frustrating first half, Foden‘s throughball to Haaland was the sort of invitation that the City striker loves and he gobbled up the opportunity in typically ruthless fashion.
He then took his own goal with incredible style and confidence as he threaded the ball into the net.
And then he linked with up Doku to prize open RB Leipzig one more time, with Alvarez smashing home the winner.
City have an incredible home record in the Champions League but it was under threat for large parts of the clash with RB Leipzig.
Guardiola’s side have not a lost home game at the Etihad in more than five years, since Lyon won 2-1 in September 2018.
That record will not be broken until 2024 at the earliest while we also remain unbeaten at home in this calendar year, with the 1-1 draw against Liverpool our only dropped points.
Our unbeaten streak in Europe now stretches to 19 matches since our semi-final second leg loss at Real Madrid.
On the way to the trophy last season, we remained unbeaten and we’ve started our defence with a 100% record from our five games so far.
Pep Guardiola reaction
“Leipzig, for the last five or six years, are always a team that qualify for the last-16, quarter-finals.
“Chelsea game, like today, we concede too much offensively. So yes you have to win duels, you have to win the actions. We didn’t do it.
“After that we played so much anxious. In football, you have to be as relaxed as possible.
“But at the same time we react well second half. The target, one game left, we are first in the group and very satisfied with the reaction at the end. The team runs, fights and had spirit.”
“It was a game of two halves, that was the worst I’ve seen us in the first half.
“We played a lot better in the second, we only needed one goal, once the first went in the motivation was there and we kept pushing, playing out football and it paid off.“
What it means
City are guaranteed top spot in Group G with a game to spare.
Guardiola’s side have maintained a 100% record in the competition to secured a seeded position in the last-16 draw with the second leg at the Etihad Stadium.
We return to the Etihad on Sunday for a Premier League clash with Tottenham Hotspur with a 16:30 (UK) kick-off.
Our final Champions League group game is away to Red Star Belgrade on Wednesday 13 December with the kick-off at 17:45 (UK).
News about Man City v Leipzig
Foden: We just needed that first goal
Phil Foden delivered a man-of-the-match performance to see Manchester City turn around a 2-0 deficit to win 3-2 against RB Leipzig at the Etihad Stadium in the UEFA Champions League. Read more
Guardiola uses Bell, Lee and Summerbee statue for inspiration
Pep Guardiola says he asked for the team bus to park in a spot which ensured he and his players had to walk past the statue unveiled today for Colin Bell, Francis Lee and Mike Summerbee. Watch more
We fight until the end, says Alvarez
Watch Julian Alvarez's post-match reaction to scoring the winner as Manchester City came back from 2-0 down to beat RB Leipzig in the UEFA Champions League. Watch more
Foden shortlisted for UCL Player of the Week award
Phil Foden's performance against RB Leipzig has seen him nominated for the UEFA Champions League Player of the Week award. Read more
City 3-2 Leipzig: Highlights
Watch our highlights package from the comeback 3-2 win over RB Leipzig. Watch more
City v RB Leipzig: Full-match replay
Watch the full 90 minutes from our Champions League clash with RB Leipzig. Watch more
Haaland becomes quickest player to 40 Champions League goals
Erling Haaland continues to score goals at an unprecedented rate. Read more
Ortega Moreno: City will fight to retain our Champions League crown
Stefan Ortega Moreno says City are ‘hungry’ to retain our Champions League crown as we this week secured progress through to the knockout stages as group winners. Read more
Leipzig comeback should help us in future, says Guardiola
Pep Guardiola says he wants his side to learn from the comeback win over RB Leipzig. Read more
Pitcam highlights: City 3-2 RB Leipzig
Watch the best moments of a stirring Champions League comeback at the Etihad Stadium from a unique angle... Watch more
Gallery: Foden inspires City comeback
Look back on the best images as Manchester City come back from two goals down to win against RB Leipzig, sealing qualification for the Champions League knockout stages as group winners. View more