GLASGOW, Scotland — Bayern Munich qualified for the Champions League knockout stage with two games to spare and eliminated Celtic with a 2-1 win over the Scottish champion, sealed by Javi Martinez’s 77th-minute goal on Tuesday.

The Spain midfielder headed home a cross by Kingsley Coman, who opened the scoring for a depleted Bayern team in the 22nd minute at Parkhead after a defensive error from a long ball.

The German club, which has now won six straight matches since the return of Jupp Heynckes as coach, is guaranteed a top-two finish alongside Paris Saint-Germain. PSG leads Group B on 12 points, three ahead of Bayern, with the two teams still to play each other in Munich.

Bayern found it much tougher against Celtic than two weeks ago, when the five-time European champions ran out easy 3-0 winners. It was to be expected, considering forwards Robert Lewandowski and Thomas Muller were out injured and Heynckes rested Mats Hummels, Thiago Alcantara and Joshua Kimmich in view of a Bundesliga match against Borussia Dortmund at the weekend.

“Last Saturday we had a tough game against a top side (in Leipzig) and today we had another difficult game. Of course it takes a lot of energy from the players,” Heynckes said. “It’s important that we have qualified, but it’s going to be difficult to finish top of the group.”

Celtic stayed in third place and is looking to seal a Europa League spot ahead of last-place Anderlecht, which has no points and no goals so far after a 5-0 loss at PSG on Tuesday.

Callum McGregor scored the equalizer for Celtic in the 74th minute.

“It’s a harsh lesson,” Celtic manager Brendan Rodgers said, “but there are so many positives from the performance.”