Karim Benzema scored twice as Real Madrid overcame Borussia Monchengladbach 2-0 at the Alfredo Di Stefano Stadium to seal a Champions League last-16 spot.
Group B was wide open heading into the final round of fixtures, but Benzema eased the growing tension on Zinedine Zidane with his 50th goal in the group stages of the competition from Lucas Vazquez's cross after just nine minutes.
Gladbach were undone once more by the Frenchman before the interval as Benzema rose to meet Rodrygo's cross to double Real's advantage with another trademark header - and the hosts saw out the second period to cement top spot.
That meant a winner in the other contest between Inter Milan and Shakhtar Donetsk would have sent Gladbach out - but the game ended in a 0-0 draw at the San Siro, sparking wild scenes of celebration among Marco Rose's players as news filtered back to Madrid.
Real Madrid: Courtois (6), Lucas (7), Varane (7), Sergio Ramos (7), Mendy (7), Modric (9), Casemiro (7), Kroos (8), Rodrygo (7), Benzema (8), Vinicius Junior (7).
Subs: Asensio (6), Arribas (6).
Borussia Monchengladbach: Sommer (7), Lainer (5), Ginter (6), Elvedi (5), Wendt (5), Kramer (5), Neuhaus (5), Plea (6), Stindl (6), Thuram (6), Embolo (5).
Subs: Herrmann (n/a), Zakaria (6), Wolf (5), Lazaro (6), Benes (5).
Man of the match: Luka Modric.
How Real rose to the occasion again
Zidane's side finished top with 10 points while Gladbach came second with eight, pipping third-placed Shakhtar due to their better head-to-head record, while Inter came fourth with six.
- How the teams lined up | Match stats
- Champions League last 16: Draw, dates, teams
- Champions League news | Fixtures | Tables
Real's shock defeat to Shakhtar last week threatened their record of qualifying from their group for the last 23 years but as so often in the competition that forms such a large part of their identity, they stood tall when it mattered most.
But this result was never really in doubt. As early as the ninth minute, they were in front through Benzema as he was too strong for Matthias Ginter, rising to plant a header low to Yann Sommer's right and into the net.
The visitors wasted a glorious chance to cancel out Benzema's opener when French winger Alassane Plea raced clear towards goal but bungled his attempted dink over Madrid goalkeeper Thibaut Courtois, sending the ball wide.
Gladbach had scored 16 goals in their previous five matches but were mostly blunt in attack and barely troubled Courtois, with Plea also missing the target in the second half.
Madrid, meanwhile, were hungry for more goals and should have stretched their lead.
Luka Modric had a strike ruled out for offside late in the first half while Benzema saw a third header saved by Sommer and then smashed a shot off the underside of the bar, while Vazquez later struck the post.
Once the final whistle went, Gladbach's players huddled around a smartphone to watch the final minutes of Inter's game against Shakhtar, erupting with joy when that match also finished to send them through by the skin of their teeth.
Inter suffer third straight group stage exit
Inter Milan were knocked out of the Champions League in the group stage for the third season in a row on Wednesday after being held to a 0-0 draw at home by Shakhtar Donetsk, who were also eliminated.
Lautaro Martinez rattled the crossbar in the seventh minute of the Group B match but Inter created few chances after that, despite dominating possession at a soggy San Siro, and mustered only four efforts on target.
Shakhtar finished level with Monchengladbach on eight points but lost out to the Bundesliga side on their head-to-head record to finish third and will go into the Europa League instead.
Inter, who could have gone through with a win, finished bottom of the group with six points after drawing three of their six games and will not even have the consolation of the second-string competition.
Inter, who thumped Shakhtar 5-0 in last season's Europa League semi-finals in August, needed to win to qualify and also to see the other match, between Real Madrid and Borussia Monchengladbach, not end in a draw.
Martinez nearly got the early breakthrough they needed but his shot thumped against the crossbar from Nicolo Barella's cross.
After that, Inter forced a succession of corners and tried their luck from long range but gave Shakhtar's 19-year-old goalkeeper Anatolii Trubin little to do. Romelu Lukaku saw a header stopped by Trubin after the break before Shakhtar began to mount some attacks of their own.
Tete, one of six Brazilian-born players in Shakhtar's starting line-up, tested Samir Handanovic with a fizzing long-range shot and Maycon sent the rebound over the bar. Trubin pushed a Christian Eriksen drive out from under the bar in stoppage time as Inter's European season came to an underwhelming conclusion.
Zidane hails 'spectacular' Madrid
Real Madrid boss Zinedine Zidane: "We played a spectacular game from the first minute to the last. We interpreted the game very well, I think it was the most complete performance of the season.
"We don't just play well under pressure, we have played well in other games too but it's true that this team has this ability to come into their own when the going gets tough.
"I've been a player and it's impossible to play like this all the time. We try to but sometimes it doesn't come off. I'm very happy for the players, because they are the most important members of this squad.
"It was fundamental that we finished first, it's the first time that has happened since I've been coach."
- Real Madrid have now progressed from all 29 of the Champions League group stages (including second group stage), the most of any side in the competition's history.
- Borussia Mönchengladbach have progressed to the UEFA Champions League knockout stages for the very first time, in what is their third participation in the competition.
- Real Madrid topped Group B with 10 points; before 2020-21, the last side to top their UEFA Champions League group having finished with no more than 10 points were both APOEL Nicosia (9) and Inter Milan (10) in 2011-12.
- Borussia Mönchengladbach's progression means that there will be four German clubs in the UEFA Champions League knockout stages for the first time since 2014-15.
Real Madrid host Atletico Madrid in La Liga on Saturday at 8pm while Borussia Monchengladbach are at home to Hertha Berlin on the same day in the Bundesliga; kick-off 2.30pm.
The Champions League last-16 draw will take place at 11am on Monday, December 14 in Nyon. You will be able to follow it across Sky Sports' platforms.