Teenager Ansu Fati became the youngest goalscorer in Champions League history as Barcelona ended Inter Milan’s hopes of reaching the last 16.
Fati, 17, came on as an 85th-minute substitute, and a minute later scored from Luis Suarez’s pass.
Barcelona, already qualified, took the lead through Carles Perez’s close-range goal on his Champions League debut.
Romelu Lukaku equalised with a low 25-yard strike but Fati’s late winner consigned Inter to the Europa League.
“I played the give and go with Luis and when I scored the stadium just went silent. I’m super happy,” said Fati, who has represented Spain at under-21 level.
“It’s a dream. Everything seems to be going at high speed. I just have to take every opportunity I’m given. But here, you look around and think: ‘what have I done’?”
Barcelona boss Ernesto Valverde praised the striker’s finishing ability and said: “Ansu is a born scorer and although he’s had some niggling pain, we wanted him to have some minutes.
“That it’s a Barca lad who’s the youngest ever scorer in this competition delights us.”
The Italians started the day second in Group F and needed to match Borussia Dortmund’s result to advance to the knockout phase of the Champions League for the first time since 2011-12.
However, Dortmund won 2-1 at home against Slavia Prague to finish second, with Inter coming third.
“Watching that Ansu Fati goal is painful, as it killed us in every way,” said Inter boss Antonio Conte.
“We were pushing, creating the chances to score and go 2-1 up. I was also disappointed for the fans at San Siro, as they pushed us from start to finish and created a wonderful atmosphere. It should’ve ended differently.
“We deserved more in this group. Still, it’s all valuable experience. We have to raise our heads again.”
Barcelona rested Lionel Messi, while Suarez began on the bench, and there was also a first Barca appearance for Brazil goalkeeper Neto following a £23.3m summer move from Valencia.
Neto saved efforts from Cristiano Biraghi and Lautaro Martinez and a number of shots from Lukaku.
Martinez twice had the ball in the net in the second half but was ruled offside on both occasions.
Fati had scored two La Liga goals for Barcelona this season and made two substitute appearances in the Champions League before this match at the San Siro.
At 17 years and 40 days old, he replaces previous record holder Peter Ofori-Quaye, who scored for Olympiakos against Rosenborg on 1 October 1997 at the age of 17 years and 195 days.
“We feel obliged to win this competition and we want to win every single match,” added Valverde.
“We’re thrilled because Inter are a really demanding rival. We played to win and my players, many of whom were making a debut of some kind, responded by showing competitive mettle.”