Goalkeeper Anatoliy Trubin scored a 98th-minute header as Benfica defeated Real Madrid 4-2 to secure a Champions League knockout place on Wednesday and deny their opponents an automatic spot in the last 16.

Benfica were heading out despite leading 3-2 with seconds of stoppage time remaining before Trubin met a free-kick to score the goal they needed to get into the playoff round on goal difference.

Madrid had hoped to finish in the top eight and go straight into the last 16, but their 15 points from eight games was not enough and they finished the match with nine men as Raúl Asencio and Rodrygo were sent off.

Andreas Schjelderup scored two goals for Benfica and Vangelis Pavlidis netted from the penalty spot, while Kylian Mbappé scored twice for Real in a hugely entertaining, end-to-end contest.

Trubin’s late goal meant Marseille slipped out of 24th spot and exit the competition after their 3-0 defeat against Club Brugge, a result that lifted the Belgian side into the playoff positions.

Anatoliy Trubin heads home in stoppage time to earn Benfica a playoff spot on goal difference. Photograph: Miguel A Lopes/EPA

Barcelona stormed back in the second half to claim a 4-1 victory over Copenhagen at the Camp Nou, sealing a top-eight finish and direct qualification for the last 16.

Goals from Robert Lewandowski, Lamine Yamal, Raphinha and Marcus Rashford ensured the Catalans finished fifth in the standings on 16 points.

Copenhagen shocked the hosts early when 17-year-old Viktor Dadason slotted the opener past Joan García in the fourth minute but the second half began with a Barcelona fightback.

Quick GuideChampions League: draw dates and playoff pathsShow

Playoff round

The teams ranked 9th-24th will contest the playoff round, with Friday’s draw determining which team from each pair below will go into which path. There are no national exclusions so, for example, Monaco will be drawn against either PSG or Newcastle, with Qarabag playing the other team.

Silver path:

(21) Monaco or Qarabag (22) v (11) PSG or Newcastle (12)

(19) Club Brugge or Galatasaray (20) v (13) Juventus or Atlético (14)

(23) Bodø/Glimt or Benfica (24) v (9) Real Madrid or Inter (10)

(17) Dortmund or Olympiakos (18) v (15) Atalanta or Leverkusen (16)

Blue path:

(22) Qarabag or Monaco (21) v (12) Newcastle or PSG (11)

(20) Galatasaray or Club Brugge (19) v (14) Atlético or Juventus (13)

(24) Benfica or Bodø/Glimt (23) v (10) Inter or Real Madrid (9)

(18) Olympiakos or Dortmund (17) v (16) Leverkusen or Atalanta (15)

Potential last 16 ties

After the playoffs are completed on 24-25 Feb, the last 16 draw will take place on 27 Feb. It will work in a similar way, with each playoff winner paired with a team who qualified automatically by finishing in the top eight. The path to the final in Budapest on 30 May will then be set.

Silver path:

Monaco/Qarabag/PSG/Newcastle v (5) Barcelona or Chelsea (6)

Brugge/Gala/Juve/Atlético v (3) Liverpool or Tottenham (4)

Bodø/Benfica/Madrid/Inter v (7) Sporting or Manchester City (8)

Dortmund/Olympiakos/Atalanta/Leverkusen v (1) Arsenal or Bayern (2)

Blue path:

Qarabag/Monaco/Newcastle/PSG v (6) Chelsea or Barcelona (5)

Gala/Brugge/Juve/Atlético v (4) Tottenham or Liverpool (3)

Benfica/Bodø/Madrid/Inter v (8) Manchester City or Sporting (7)

Olympiakos/Dortmund/Leverkusen/Atalanta v (2) Bayern or Arsenal (1)

Photograph: Mohammed Badra/EPA

Thank you for your feedback.

Lamine Yamal set up Lewandowski to equalise in the 48th minute, before scoring himself in the 60th with a deflected effort that left Copenhagen keeper Dominik Kotarski helpless. Raphinha made it 3-1 from the penalty spot after Lewandowski was fouled, and Rashford added a fourth with a free-kick in the 85th minute.

Sporting Lisbon twice came from behind before Alisson Santos netted an added-time winner as they beat Athletic Bilbao 3-2 away to reach the last 16 after a frenetic final group game.

Sporting needed a win to give themselves a chance of a top-eight spot, but Oihan Sancet got the home side off to a perfect start with a third-minute goal. The visitors levelled nine minutes later through Ousmane Diomande’s unstoppable header from Maximiliano Araújo’s corner.

Alisson Santos prepares to be mobbed by his teammates after his late winner. Photograph: César Manso/AFP/Getty Images

Sporting went behind again after 28 minutes when Gorka Guruzeta fired home but the Portuguese side refused to lie down and equalised once more through a brilliantly worked move, Francisco Trincão slicing through the middle and steering the ball past Unai Simón.

Sporting looked set for the playoffs until they broke deep into second-half stoppage time and though Luis Suárez had his shot blocked by Simon, Santos followed up and rifled the ball home to see his side safely through.

Norwegian side Bodø/Glimt staged a remarkable comeback to defeat Atlético Madrid 2-1 away from home, securing their place in the competition’s knockout stage.

Alexander Sørloth put the hosts ahead in the 15th minute, meeting David Hancko’s pinpoint cross with a powerful header but the visitors responded in the 34th minute when Fredrik Bjarko assisted Fredrik Sjøvold to level.

The decisive moment came in the second half when Kasper Høgh latched on to a loose ball in the 59th minute, striking from close range to silence the home crowd. Atlético pushed for an equaliser but they were unable to pierce the Norwegian defence.

Bodø/Glimt’s Kasper Høgh (No 9) scores their winner. Photograph: Susana Vera/Reuters

Intern scored twice late in the game to earn a 2-0 victory over hosts Borussia Dortmund but it was not enough for a top-eight finish, with both teams going into February’s playoffs for a spot in the knockout stage.

Federico Dimarco curled in a sublime free-kick in the 81st minute before Andy Diouf added another goal in stoppage time to snap Inter’s three-game losing run in the competition.

Harry Kane came off the bench to score an 84th-minute winner for Bayern Munich as they edged PSV Eindhoven 2-1 away to finish second in the group phase and end their hosts’ hopes of continuing in the competition.

Olympiakos grabbed a playoff spot with a 2-1 win away at Ajax, Santiago Hezze’s 79th-minute goal proving the winner.

Monaco and Juventus played out a low-key 0-0 draw in the Principality, a cautious game that was still enough to send both sides through to the playoffs.

Atalanta had to settle for a playoff spot after a 1-0 defeat at Union Saint-Gilloise, Bayer Leverkusen finished 16th after thumping Villarreal 3-0 and Cypriot side Pafos ended a creditable campaign with their second victory, a 4-1 win over Slavia Prague.