Real Madrid closed the gap on Barcelona to just two points at the top of La Liga, but will be praying injuries to Gareth Bale and Luka Modric don't derail their season. Both Los Blancos stars were substituted as Carlo Ancelotti's side struggled to overcome a spirited Malaga, who had chances to snatch a draw. Cristiano Ronaldo missed a penalty but provided goals for Sergio Ramos and James Rodriguez, before adding the third himself, as Madrid kept within touching distance of league leaders Barcelona. Sergio Ramos celebrates scoring for Real Madrid in the 24th-minute against Malaga . Real Madrid captain Ramos celebrates with his team-mate Cristiano Ronaldo . James Rodriguez made it 2-0 for Real Madrid in the 69th-minute after Ronaldo had missed a penalty . Malaga then pulled one back but Ronaldo look delighted after making up for his earlier miss to make it 3-1 . Real Madrid: Casillas, Pepe, Ramos, Marcelo, Arbeloa (Carvajal 76'), Kroos, Rodriguez, Modric (Illarramendi 60'), Isco, Ronaldo, Bale (Hernandez 5') Subs not used: Navas, Silva, Fernandez, Jese . Booked: Arbeloa, Kroos . Goals: Ramos 24' Rodriguez 69' Ronaldo 90' Malaga: Kameni, Angeleri, Roseles, Boka, Sanchez, Amrabat, Garcia, Recio (Damian Tissone 75'), Castillejo (Horta 81'), Darder (Duda 87), Juanmi . Subs not used: Guerra, Ochoa, Torres, Filipenko . Booked: Sanchez, Damian Tissone . Goals: Juanmi 71' After just four minutes, Bale's game was over. The Welshman tenderly touched his calf and made a pulling motion with his hands to the bench as he left the pitch, which might imply internal muscle damage. Given that Karim Benzema was injured after a brutal Champions League encounter with City rivals Atletico Madrid in midweek, Bale's injury took the famous "BBC" strikeforce just down to C. That's the grade you'd give it too, in 2015, when compared to the performances of Barcelona's trio. Isco came in for Benzema, with the Frenchman's injury solving a problem that was brewing at Real Madrid, with Carlo Ancelotti having to choose between the former Malaga man, and James Rodriguez. The latter was chosen over the former to face Atletico, leading to stories of angst on Isco's part, but the issue was resolved by Benzema's timely absence. Modric, meanwhile, was taken out by a Recio challenge in the second half. It wasn't too fierce a tackle, but the Croatian took a strong knock to his knee and is now a doubt for Wednesday's second leg against Atletico. Malaga, having beaten Barcelona at Camp Nou earlier this season, and drawn with champions Atletico Madrid last week, are no La Liga whipping boys and they came to the Santiago Bernabeu with the belief they could win. Nordin Amrabat, on loan from Galatasaray, charged forward battling with Pepe, escaped the Real Madrid defender and crossed for Juanmi, but the forward couldn't connect and the chance was gone. The Dutchman stung Iker Casillas' fingertips with a strike from distance, the veteran stopper tipping his effort behind for a corner. Carlos Idriss Kameni was forced into a similar save at the other end, spectacularly flicking a header from Bale's replacement, Javier Hernandez, over the bar. Gareth Bale went down injured after less than five minutes at the Bernabeu . The Welsh forward was forced to go off to be replaced in the early stages of proceedings . Ramos tucks the ball in to open the scoring for Real Madrid at the Bernabeu . The defender slides on his knees in front of the Real Madrid fans after netting . Real Madrid broke the deadlock in controversial fashion, when Ronaldo fired in a free kick from the left and Ramos rammed home from close range. The defender seemed fractionally offside, but despite Kameni's cries, the goal was allowed to stand. The Cameroonian goalkeeper was called into action again shortly afterwards, making a fine save down to his right from a James volley. With the most expensive player in the world off the pitch, the second most expensive was having fun. Ronaldo pulled off a quite ridiculous backheel-nutmeg on Marcos Angeleri. In the following minute Ramos had the ball in the net again, nodding home a Toni Kroos free-kick, but this time the officials spotted he was offside and ruled it out. Malaga flew down the other end and created a magnificent opportunity, which Sergi Darder blazed over the bar when he should have found the net. Juanmi's cross was half-cleared by Marcelo and Darder pounced, but lacked balance and spooned his strike off-target from eight yards. Amrabat, flying down the right early in the second half, tried to find Juanmi with a low cross, but it flew past the forward and Casillas gathered it. Ronaldo had the perfect opportunity to put the game beyond Malaga when James was taken down in the box by Samu Castillejo, but lacked his characteristic cool and fired the penalty against the left upright. Real Madrid goalkeeper Iker Casillas dives to the floor to grab the ball against Malaga during the La Liga clash . Real Madrid forward Ronaldo (right) in action against Malaga's Samuel Garcia at the Bernabeu . Real Madrid manager Carlo Ancelotti watches on from the sidelines during his side's clash with Malaga . But Real Madrid didn't have long to wait for their second, with James scoring in spectacular fashion just a minute later. He played two one-twos on the edge of the box with Isco and Ronaldo, before lashing the ball into Kameni's top right corner. Game over? Not quite. Malaga were straight down the other end and on the scoresheet, with Roberto Rosales whipping the ball in from the right for Juanmi to head home. Amrabat had a chance to run through after a Marcelo mis-step - this was a rare poor performance for the Brazilian - but Kroos resorted to a blatant kick to stop him. The German went into the book, with the foul a symbol of how Madrid were struggling to prevent the Andalusian side from getting forward on the break. Ronaldo saw his second-half penalty hit the post after Malaga goalkeeper Carlos Kameni had gone the right way . Real Madrid forward Ronaldo looks frustrated after missing a penalty during the second half . But Rodriguez soon doubled Real Madrid's lead just a couple of minutes after Ronaldo had missed the penalty . Ronaldo celebrates after securing the 3-1 victory late on after Malaga had pulled one back . Ronaldo's evening was saved on a personal level at the end, with Hernandez selflessly squaring the ball for the forward to tap home at the far post. His celebration was excessive, considering Madrid had essentially won the game and it was a simple finish, but that's what happens when you have to keep up with the Joneses. Or in this case, the Messis. The Argentine had scored for Barcelona earlier, so Ronaldo would have left frustrated had he not been able to replicate Messi's effort, grabbing his 39th goal of the season in La Liga, and his 50th in all competitions. Ronaldo became the first ever player to net 50 goals in five consecutive seasons, an incredible statistic, but Ancelotti's mind will now turn to Wednesday night and another incredible statistic. He has faced Atletico Madrid seven times so far this season and not won a single game. Will he be forced to try it without Modric and Bale in the eighth?
Sergio Ramos opened the scoring for Real Madrid in the first half at the Bernabeu .
Cristiano Ronaldo then hit the post with a penalty before James Rodriguez nets .
Juanmi pulled one back for Malaga but Ronaldo scored late on to secure the win .
Gareth Bale and Luka Modric go off injured for Real Madrid .