The visitors controlled the game but found it difficult to break down an Alaves side that had the best home defensive record in the division. Eder Militao was lucky not to concede an early penalty for his challenge on Aleix Vidal, who was instead booked for diving.
Ramos broke the deadlock with a header when picked out by a pinpoint Toni Kroos free kick, before conceding a penalty when he caught Joselu in the face. Carvajal scored the winner when Luka Modric's cross was headed against the post by Isco and the full-back reacted first inside the 6-yard box.
Real Madrid came into this game in their best form of the season, with a win against Real Sociedad last weekend and some sparkling football against Paris Saint-Germain in midweek. Here they handled a different kind of task well, with a hostile Mendizorrza crowd and driving Basque rain. It was the kind of performance and result that suggests they'll challenge for the title.
Madrid's midfield dominance was total as they patiently waited for opportunities. For the opener, Kroos' delivery and Ramos' header were straight out of the Real Madrid textbook. The winner saw two unlikely protagonists with Isco's header and Carvajal giving the visitors the three points.
Despite their midfield control, Madrid found Alaves' disciplined defence hard to break down, often facing 11 players behind the ball. Sergio Ramos will have been disappointed to concede the Alaves penalty that Lucas Perez dispatched to get the home side back into the game.
Manager rating out of 10
8 -- Zinedine Zidane made four changes from the draw with Paris Saint-Germain as he looks to replicate the rotating formula that won Madrid the league in 2017. The team had an interesting shape without a real left-sided attacker, with a fluidity to the movements of Isco and Karim Benzema up front. Zidane will know just how important these three points should prove to be.
Player ratings (1-10; 10 = best. Players introduced after 70 minutes get no rating)
DF Dani Carvajal, 8 -- Got forward frequently down the right and appeared in exactly the right place at the right time to score Madrid's winner.
DF Eder Militao, 7 -- Yet to settle as a Real Madrid player, he was fortunate not to give away a penalty early on. Recovered well and has the kind of pace that suggests he'll eventually make an able deputy for Raphael Varane.
DF Sergio Ramos, 7 -- Led by example in difficult weather conditions for a centre-back. A deft header got Madrid the crucial opener, before giving away the penalty for the equaliser.
DF Marcelo, 7 -- Played well without quite reaching the level he did against PSG in midweek.
MF Casemiro, 7 -- Had less defensive work to do than usual due to Alaves' conservative approach, but remains one of Madrid's most important players in away games like these.
MF Toni Kroos, 7 -- Kroos has been in arguably the best form of his Real Madrid career lately. His set piece deliveries are peerless, providing a delightful ball here for Ramos' header.
MF Luka Modric, 7 -- Rested against PSG in midweek, he brought fluency to the midfield and helped control the play. His cross made the Real Madrid winner.
MF Isco, 7 -- His second start in a week after coming in from the cold and excelling against PSG. He should have scored midway through the first half, shooting over the bar. Headed against the post before Carvajal scored.
FW Gareth Bale, 5 -- Quiet on his first Real Madrid start since Oct. 5. He was much less involved than in his substitute appearances this week.
FW Karim Benzema, 6 -- In imperial form in recent weeks, La Liga's top scorer shone less than he has done lately but played an important part.
FW Rodrygo, 6 -- Quiet after replacing Gareth Bale.
MF Valverde, NR -- Gave Real Madrid fresh legs in midfield and had the chance to score a third goal deep in added time.
DF Mendy, NR -- Came on in added time to defend Madrid's lead.