MADRID — Cristiano Ronaldo has set yet another Champions League record, scoring in Real Madrid’s 3-2 win over Borussia Dortmund on Wednesday to become the first player to find the net in all six group-stage matches.

Madrid had already guaranteed second place behind Group H winner Tottenham, which defeated APOEL 3-0 at Wembley Stadium to reach 16 points.

Madrid ended with 13 points, and Dortmund and Cypriot club APOEL finished with two points each. The German club finished third because of a better goal difference and will now play in the Europa League.

Madrid led 2-0 after Borja Mayoral opened the scoring and Ronaldo netted his ninth group-stage goal this season. Dortmund equalized with two goals by Pierre-Emerick Aubameyang, one in each half, but Lucas Vazquez got the winner in the 81st minute at the Santiago Bernabeu Stadium.

Ronaldo, the all-time leading scorer in the Champions League with 115 goals, netted with a well-placed shot from outside the area after a pass by Mateo Kovacic in the 12th minute, curling the ball into the top corner by the far post.

“We wanted to finish the group stage well, with a win, and we did so,” Ronaldo told UEFA.com. “I scored, I helped the side win. It’s a nice goal and the record is important, too. I’m delighted.”

Ronaldo had scored 11 group-stage goals two seasons ago, the most ever in the competition. He also holds the record for more Champions League goals in a season after scoring 17 in 2013-14. Earlier this year he became the player with the most penalty kick goals in Champions League history, with 12, one more than Lionel Messi.

“Any football fan enjoys watching players like Ronaldo,” Dortmund coach Peter Bosz said. “His presence and desire to score is so great. He’s aggressive. It’s brilliant for any football fan to watch.”

Ronaldo had several other chances to score a second goal and had a strike disallowed for offside near the end of the game.

The Portugal forward has been struggling in the Spanish league, with only two goals in 10 matches, but has scored nine times in his six Champions League games.

Madrid was in control throughout the match on Wednesday, but Dortmund threatened in counterattacks with its speedy forwards.

Mayoral put the hosts ahead eight minutes into the match with a close-range shot after a move that started with a pass by Ronaldo to Isco inside the area.

After Ronaldo had doubled Madrid’s lead, Dortmund pulled a goal back just before halftime with a diving header by Aubameyang following a cross from the left by captain Marcel Schmelzer.

Aubameyang equalized early in the second half with a shot over Keylor Navas after his initial attempt was stopped by the Madrid goalkeeper.

Vazquez’ winner came with a low shot from just outside the area after being set up by Theo Hernandez with a header.

“We didn’t start well enough,” Bosz said. “We need to show that we can compete at this level and we did that in both halves. I think that’s good for our confidence.”

With nothing to play for in the final group game, Madrid coach Zinedine Zidane rested some regular starters, including Karim Benzema, Luka Modric and Marcelo. He also added some youngsters during the match, including Marcos Llorente, Dani Ceballos and Marco Asensio.

Madrid defender Raphael Varane left the game before halftime because of an apparent injury.

“Varane got injured and things got more difficult,” Zidane said. “We changed the setup and system. The final half hour was great, we changed tactics again and things worked out.”