Lucas Vazquez grabbed the winner nine minutes from time for the European champions, who were already guaranteed to go through to the last 16 as runners-up in Group H to Tottenham Hotspur.
Ronaldo took his tally to nine goals in six Europan appearances this season with a spectacular long-range effort into the top corner after Borja Mayoral's opener to give Real a 2-0 lead inside 12 minutes.
Pierre-Emerick Aubameyang continued his excellent record against Madrid with a quickfire double either side of half-time to bring Dortmund level.
But despite Vazquez's late strike, the Germans drop into the Europa League with a record low two points thanks to their better goal difference over APOEL Nicosia, who were defeated 3-0 at Spurs.
Real were, though, hit by a fresh injury blow as French international defender Raphael Varane limped off just before half-time holding his left leg.
Zinedine Zidane now faces a defensive crisis ahead of the visit of Sevilla on Saturday with captain Sergio Ramos, right-back Dani Carvajal and holding midfielder Casemiro all suspended.
"With Rafa he has done some damage to himself, but we will see tomorrow when we do the scans as always," said Zidane.
"He won't be there Saturday that is for sure. We have to look for solutions."