Mario Pasalic turned in a cross to the stun the hosts after 15 minutes before Merih Demiral headed in a second.
Marcus Rashford pulled one back early in the second half with a neat finish.
Harry Maguire then drove in an equaliser in the closing stages before Ronaldo headed in the dramatic winner.
It was a stunning finale to an exhilarating game as boos at half-time turned into delirious cheers at full-time after one of the most sensational Champions League games at Old Trafford.
The result means United go top of Group F with six points from three games.