Barca need two more points to wrest the league crown back from their arch rivals and secure a fourth title in five years and a win at third-placed Atletico Madrid on Sunday would be enough for Tito Vilanova's side.
Barca have 88 points from 34 of 38 matches, with Real in second on 80 from 35. Atletico, eight points further back in third, secured a berth in the Champions League group stage with a 3-1 win at struggling Celta Vigo earlier on Wednesday.
Both matches had been brought forward due to the King's Cup final between Real and Atletico on Friday May 17.
Real coach Jose Mourinho, who seems certain to leave after a disappointing season, was again whistled by a significant section of the home support at the Bernabeu when his name was read out before kickoff.
The Portuguese has clashed with several members of the squad in recent weeks, including club captain Iker Casillas, who was again left out of the team, and fans cheered when the Spain goalkeeper's name was read out in the list of substitutes.
Malaga's Chilean coach Manuel Pellegrini, whom Mourinho replaced when he joined from Inter Milan in 2010, was also given a warm reception.
"The fans do what they think is right," Mourinho's assistant Aitor Karanka told a post-match news conference.
"And the coach does what he thinks is right to get the best performance from the team to win matches," he added.
Centre back Raul Albiol nodded Real in front from a corner in the third minute before Roque Santa Cruz, who scored in Malaga's 3-2 home win against Real in December, levelled after a quarter of an hour.
The match turned in the 21st minute when Malaga defender Sergio Sanchez was shown a straight red card for bringing Ronaldo down in the area.
Although the Portuguese had his spot kick saved by Willy Caballero, who injured his ankle in the process and had to be replaced by Carlos Kameni, Ronaldo netted with an indirect free kick close to goal in the 26th minute.
It was his 200th goal on his 197th appearance for Real since joining from Manchester United for a record fee in 2009 and his 34th in La Liga this season.
Mesut Ozil finished off a swift breakaway to make it 3-1 to Real in the 34th minute, Vitorino Antunes pulled a goal back for Malaga two minutes later and Ronaldo set up Karim Benzema to make it 4-2 on the stroke of halftime.
The second half was much less eventful until Luka Modric struck a long-range shot in off a post in the 63rd minute.
Malaga centre back Martin Demichelis was shown a second yellow card for a 73rd-minute foul on Ronaldo and sent off and Ozil then went over awkwardly with around 10 minutes left and appeared to injure his right knee.
The German international was carried off on a stretcher for treatment, reducing Real to 10 men as they had already made their three substitutions.
The stadium was emptying when substitute Angel Di Maria completed the rout in added time with a curling shot into the corner from the edge of the area.
"We have to be united and finish the league off on a winning note as we owe that to our fans," Albiol said in an interview with Spanish television broadcaster Canal Plus.
"And the most important thing is to achieve the objective of winning the King's Cup," added the Spain international.
Atletico trio Diego Costa, Juanfran and Radamel Falcao netted second-half goals at Celta to put the 2010 and 2012 Europa League winners back in Europe's elite club competition for the first time in three years.
Atletico climbed on to 72 points with three games left, 14 ahead of fourth-placed Real Sociedad, who have a match in hand.
Malaga's hopes of a return to Europe's elite club competition after they reached the quarter-finals this term are all but over following Wednesday's reverse.
The Qatar-owned club are sixth on 53 points, five behind Sociedad and three adrift of fifth-placed Valencia.
Brazilian striker Costa broke the deadlock in Vigo in the 47th minute, diving to head home after a well-worked near-post corner move was flicked on by Miranda.
Full back Juanfran's long-range shot was deflected past Javi Varas in the 66th, but Celta threatened a comeback when Augusto Fernandez's shot squirmed beneath Thibaut Courtois in the 84th.
Colombia striker Falcao made sure of the win lashing a shot high into the net four minutes from time, to take his tally for the season to 27.
Celta, promoted at the end of last season, are running out of time to avoid a swift return to the second division as they lie 19th with 31 points, two short of safety, but having played a game more than their relegation rivals.