The 17-year-old Guinea-Bissau-born attacker picked up a Luis Suarez cross to fire home four minutes from time to become the youngest player to score in the Champions League.
That record had been held since 1997 by Ghana's Peter Ofori-Quaye.
Barcelona were already through to the knockout stages as Group F winners and they left six-time Ballon d'Or winner Lionel Messi at home.
But Serie A leaders Inter needed a win over the La Liga leaders or to match Borussia Dortmund's result at home to Slavia Prague to qualify on their superior head-to-head record.
Instead the Germans made it through to the knockout rounds with a 2-1 win to finish three points ahead of third-placed Inter, who go into the Europa League.
In other games holders Liverpool safely negotiated Tuesday's trip to Salzburg to take their place in the last 16 while Chelsea are also through, but Ajax suffered a shock group-stage exit.
Jurgen Klopp's side just needed to draw in Austria to keep alive their bid to retain the European Cup, and they duly beat Salzburg 2-0 thanks to two goals in two second-half minutes, by Naby Keita and Mohamed Salah.
"What a team," Klopp told BT Sport. "What an effort. It was a tough game."
"We scored two wonderful goals. We could have scored six or seven which is crazy. We won the group, we won the game, all good."
Ancelotti sacked by Napoli
Napoli made sure of their progress by trouncing Genk 4-0 in Italy with Arkadisuz Milik scoring a first-half hat-trick, the third goal coming from the penalty spot.
Dries Mertens converted another spot-kick in the second half to seal the win, but the Italian side still sacked coach Carlo Ancelotti in the wake of the game.
There was high drama in Group H as Valencia beat Ajax 1-0 in Amsterdam, Rodrigo Moreno's strike taking the Spaniards through to the last 16 at the expense of last season's semi-finalists, and leaving their hosts stunned.
Ajax had again been impressive this season but were left to rue their inability to win either of their two matches against Chelsea, as Frank Lampard's team progressed in second place, a point ahead of the Dutch giants, thanks to a 2-1 victory against Lille.
Tammy Abraham and Cesar Azpilicueta netted first-half goals for Chelsea, who held on after Loic Remy pulled one back for Lille.
Chelsea, the 2012 Champions League winners, finish level on points with Valencia but come second due to their inferior head-to-head record.
"The Champions League is where Chelsea belong. We knew it was a tough group. We had to fight and recover after losing against Valencia at home in our first game," Azpilicueta told BT Sport.