The win, sparked by Kylian Mbappe's equaliser, delayed Barcelona's coronation, though the leaders remain four points ahead with a game in hand and can clinch their 28th La Liga title with a victory against Espanyol on Thursday.
Despite a crippling injury crisis that left 12 players sidelined, Carlo Ancelotti's side showed resilience. "We didn't give up despite the absences, which is rare," Ancelotti said in his post-match press conference.
"The team's attitude was exceptional, and the players who stepped up delivered. We took 40 shots—something I've never seen."
The match began with a shock as Mallorca's Martin Valjent capitalised on a Dani Ceballos error to fire the visitors ahead in the eighth minute.
Real Madrid, reeling from their recent Clasico defeat, struggled to break down Mallorca's resolute defence, with goalkeeper Leo Roman making five first-half saves, including stops from Jude Bellingham and Luka Modric.
Ancelotti's side pushed relentlessly after the break. Modric, orchestrating play, set up Mbappe for a clinical 68th-minute equaliser, as the Frenchman turned past two defenders and slotted home.
Roman's heroics continued, denying Mbappe again and thwarting substitute Gonzalo Garcia late on. But in the fifth minute of stoppage time, after Real Madrid's 26th corner, Jesus Vallejo's flick-on found Ramon, who poked past Roman to spark wild celebrations at the Santiago Bernabeu.
"We fought until the last second," Ancelotti said. "We'll keep winning what's left and see what happens. Anything is possible." The Italian, set to depart for the Brazil national team job after the season, reflected on his time at Real Madrid: "Sitting on this bench has always been special. I leave with peace of mind, knowing we've given everything."
Mallorca's Jagoba Arrasate, marking his 500th senior managerial game, praised his team's effort despite the defeat. "We pushed Real Madrid to the limit," he said, per an X post from Mallorca's official account. The islanders remain in the hunt for a first European spot in 22 years, with their fate partly resting on Rayo Vallecano's upcoming results.
Real Madrid's title defence hangs by a thread, but Ramon's late strike ensures they won't go down without a fight. Barcelona, however, need only a win to end the race.