LISBON, Portugal — Napoli won 2-1 at Benfica but both teams qualified for the knockout stage of the Champions League on Tuesday after Besiktas fell to a surprise 6-0 thrashing at Dynamo Kyiv.

Substitute Dries Mertens, who scored two goals in the 4-2 win against Benfica in Italy, changed the Group B match after coming on. The Belgium international set up the opener for Jose Callejon on the hour mark before securing the win in the 79th as Napoli topped its Champions League group for the first time.

It was meant to be a battle to advance at Estadio da Luz but it turned out to be a shootout for top spot as Besiktas collapsed in Ukraine.

Both Benfica and Napoli had squandered several earlier opportunities to make it to the last 16, with the Italian side almost becoming the first team in Champions League history to advance from the group stage after only three matches — before losing to Besiktas and drawing its next two games.

Both teams had eight points coming into the match, one more than Besiktas, and Napoli knew a draw would be enough, having already defeated Benfica.

It was an end-to-end start to the match but there were few clear chances and the tempo started to fall as the news filtered through that Besiktas was losing.

Napoli goalkeeper Pepe Reina had been the busier of the two shotstoppers in the first half but Napoli appeared more determined after the break. Callejon should have broken the deadlock four minutes into the second half but fired wide from a great position.

Mertens was brought on in the 57th and had an immediate impact, with a lovely through ball to Callejon who dinked it over the onrushing Ederson.

Mertens got on the scoresheet himself in the 79th, carving out space just inside the area, following a one-two between Callejon and Faouzi Ghoulam, and curling into the bottom left corner.

Napoli gifted Benfica a consolation goal three minutes from time when Raul Albiol was caught napping. He should have easily cleared a long ball but Raul Jimenez seized the moment and fired past Reina.