Real remain top with 48 points, one more than Barca and also with a game in hand, but the loss of world player of the year Ronaldo through a ban could cause problems.
"I am sorry to everyone and especially to Edimar for my impulsive act in today's game," Ronaldo said on his Twitter account.
His great rival Lionel Messi and Neymar hit second-half braces for Barca after Gerard Pique celebrated his 200th La Liga appearance with a volley that clipped off Domingo Cisma and into the roof of the net 10 minutes before the break.
Neymar was upended in the box by Sergio Pelegrin and Messi scored the penalty after 55 minutes. Elche midfielder Faycal Fajr was dismissed for a second yellow card two minutes later.
Messi was the provider twice for Neymar who finished clinically after 69 and 72 minutes before the Argentine got his second two minutes from the end.
Messi has now equalled the record of doubles scored in La Liga after notching up his 77th to match the total set by Telmo Zarra, of Athletic Bilbao, in the 1940s and 1950s. It is the latest in a long line of records for the striker, who became the highest scorer in La Liga history earlier this season.
There was still time for Pedro to get the sixth from close range after being found by Neymar.
"After the first goal it was easier and we were able to control the game," Barca coach Luis Enrique told reporters.
"This was a typical game during the season and they are not easy to win so I am happy with the way the team played over the 90 minutes."
Livewire Griezmann
Real's Ronaldo kicked out at defender Edimar with seven minutes to go and also appeared to throw a punch as the visitors struggled to create chances but they were gifted the win when a Gareth Bale free kick was handled by Fede Cartabia in the area.
Cartabia was also sent off for a second bookable offence and, with Ronaldo off the pitch, Bale fired home the winning penalty with two minutes left.
Nabil Ghilas gave Cordoba the lead from the penalty spot with two minutes played following a handball by Sergio Ramos.