The Hammers started strongly and took the lead after 30 minutes when Said Benrahma's shot took a huge deflection off Raphael Varane to beat David de Gea.
But Ronaldo equalised just five minutes later at the second attempt after a fine cross by Bruno Fernandes. Incredibly, it was Ronaldo's fourth goal in a week since returning to Man Utd this summer from Juventus.
United had a number of chances and penalty appeals turned down until substitute Jesse Lingard lashed home a brilliant winner one minute from time.
But deep into injury time, West Ham could have earned a point as De Gea saved substitute Mark Noble's penalty.
The three goals came from unlikely scorers as Thiago Silva, N'Golo Kante and Antonio Rudiger all found the net.
It was a dominant victory for the Blues, who had 22 shots in the game to Tottenham's seven.
Man Utd also have 13 points but have a -2 goal difference on their two rivals.
In the other game on Sunday, Brighton beat Leicester 2-1 in a game marred by VAR controversy.
Neal Maupay opened the scoring from the penalty spot before Danny Welbeck doubled the lead with a header.
Jamie Vardy reduced the arrears on 61 minutes but Leicester were denied a point when VAR ruled out an equaliser for a Harvey Barnes offside.
Brighton move into the top four, while Leicester stay in the bottom half of the table.
View our detailed player statistics for the Premier League at the link below.