Sebastien Haller continued his stunning form in the Champions League to secure top spot in Group C for Ajax.
Ajax’s perfect record looked to be in danger as they fell behind against Besiktas to a penalty from Rachid Ghezzal.
However, former West Ham striker Haller netted the equaliser shortly after half-time and then grabbed the winner 15 minutes later.
Ajax rally to beat Borussia Dortmund and book place in knockout stages
The 2-1 victory moves Ajax onto 15 points, with Borussia Dortmund and Sporting Lisbon both on six points ahead of their meeting later on Wednesday evening.
Haller’s double means he is the first player in Champions League history to score nine goals in his first five appearances in the competition.
He is also only the fourth player to score in his first five Champions League appearances, after Alessandro Del Piero (1995), Diego Costa (2014) and Erling Haaland (2019).
Borussia Dortmund are out of the Champions League after losing 3-1 at Sporting Lisbon.
Pedro Goncalves put Sporting 2-0 ahead in the first half before Dortmund had Emre Can sent off in the 75th minute. Goncalves missed a chance for a hat-trick when he saw a penalty saved, but Pedro Porro headed in the rebound.
Donyell Malen scored a late consolation goal for Dortmund, who are guaranteed to finish third and go into the Europa League.
Emil Forsberg and Christopher Nkunku both scored twice as RB Leipzig won 5-0 at Club Brugge in Group A. Both sides are on four points heading into the final matchday, with Manchester City top after their 2-1 win over Paris Saint-Germain.
Elsewhere, Napoli suffered a setback in the Europa League as they were beaten 2-1 by Spartak Moscow.
Aleksandr Sobolev netted both goals for the Russian side, who move level on seven points with Napoli in Group C.
Legia Warsaw are on six points and Leicester are on five. They meet at the King Power Stadium on Thursday.
Sterling may be denied Real Madrid move as he prepares for exit - Paper Round
Opinion: Dortmund demolition proves Ajax are ready to upset established order again