WARSAW, Poland — Poland secured its spot in next year's World Cup in Russia with a 4-2 win over Montenegro on Sunday in European qualifying.

Montenegro scored late goals through substitute Stefan Mugosa and Zarko Tomasevic to level at 2-2 and ensure a nervy finale for Poland, which needed just a point to qualify as Group E winner.

Robert Lewandowski capitalized on a defensive mistake to restore the home side's lead in the 85th minute with his record 16th goal in European qualifying before Filip Stojkovic's own-goal ended any further suspense.

Early goals from Krzysztof Maczynski and Kamil Grosicki had put Poland 2-0 ahead by the break.

Poland finished top on 25 points. Denmark came second on 20 points and booked a playoff spot despite being held to a 1-1 draw by 10-man Romania in Copenhagen.

Lewandowski, who already shared the record with Cristiano Ronaldo for 15 goals scored in a qualifying campaign, was unable to add to his tally in the first half, though he displayed great awareness to set up Grosicki for Poland's second when he had his back turned to goal.

The home side appeared complacent after the break, and Mugosa scored with a spectacular bicycle kick before Tomasevic equalized. Another goal from Montenegro would have put Denmark - then leading 1-0 against Romania - through as group winner at Poland's expense.

But Lewandowski allayed the home fans' fears when he raced onto a sloppy back-pass and beat goalkeeper Danijel Petkovic to the ball before shooting into the unguarded net.

___

DENMARK IN PLAYOFFS

Danish fans had a mixed reaction to news of Poland's early goals in Warsaw. Denmark could still qualify automatically with a win over Romania if Poland lost at the same time.

The home side endured a frustrating first half with a goal from Nicklas Bendtner ruled out for offside. TV replays showed otherwise.

Christian Eriksen finally scored with a penalty on the hour mark after Cristian Ganea had hauled down Bendtner.

Ganea, who was booked, earned his second yellow card minutes later for dragging down Yussuf Poulsen.

However, Ciprian Deac scored late to salvage a 1-1 draw for Romania.

Denmark, with 20 points, gets a playoff spot as one of the eight best runners-up from Europe's nine groups.

Montenegro finished with 16 points, ahead of Romania on 13.

Armenia ended on seven points after drawing with host Kazakhstan 1-1 in Astana.

Kazakhstan finished bottom with three points.

___

More AP World Cup coverage: www.apnews.com/tag/WorldCup