
Barcelona remain just a point behind the European champions having played a game more as Neymar and Lionel Messi both scored twice in a 6-0 win at 10-man Elche.
Champions Atletico Madrid are four points off the top after Antoine Griezmann's double helped them to a 3-1 win over Rayo Vallecano.
Real got off to the worst possible start when Sergio Ramos handled inside his own area and Nabil Ghilas slotted home the resultant penalty.
Karim Benzema levelled from James Rodriguez's corner midway through the first-half, but Ronaldo's frustration at a poor performance seemed to have cost his side the chance of victory when he lashed out at Edimar seven minutes from time.
However, the numbers were levelled up when Fede Cartabia was shown a second yellow card for handling Bale's free-kick inside the area, and in Ronaldo's absence, the Welshman took responsibility from the spot to secure all three points.
The enthusiasm generated by Madrid's first visit in 44 years ensured there was a full house at the Nuevo Arcangel and the home fans had plenty to cheer within the first two minutes as Manchester United reject Bebe saw his shot cannon off Ramos's arm and Ghils converted from the spot.
Slowly, though, Madrid began to find their feet and drew level on 27 minutes when Rodriguez's corner was flicked on by Bale and Benzema slammed home his 15th goal of the season from close range.
Cordoba were left to rue a host of missed opportunities to seal a famous win after the break with Florin Andone's attempted lob which struck the crossbar the closest they game to regaining the lead. AFP