MADRID (AP) — Lionel Messi scored a hat trick to give Barcelona a 4-3 win at 10-man Real Madrid in an electrifying and contentious "clasico" match that kept the three-way Spanish league title race wide open.
The result means Atletico Madrid now tops the table, with Madrid level on points in second and Barcelona a point behind in third with nine games remaining as the title race shapes up to be the closest in years.
In a game that saw three penalties, a red card and a host of missed chances, Andres Iniesta set the tone by rocketing home an early opener, only for Karim Benzema's brace to put the hosts ahead by the 24th.
The teams went into the break level at 2-2 after Messi slotted in an equalizer, only for Cristiano Ronaldo to re-establish Madrid's lead with a 55th-minute penalty.
But Messi scored a pair of penalties after that — including the 65th-minute equalizer after Sergio Ramos was sent off — to end Madrid's 31-game unbeaten run stretching back to the last "clasico" in October.
"It's unusual to see so many penalties called in a clasico," Barcelona fullback Jordi Alba said. "This win will give us a lot of momentum going forward."
While Madrid coach Carlo Ancelotti tried to defuse tension surrounding the three penalties, Ronaldo did not.
"I don't want to say the referee favored one team more than the other, but he favored Barca a little more," Ronaldo said.
Earlier, Diego Costa's 23rd goal followed Gabi Fernandez's opener as Atletico beat 10-man Real Betis 2-0 and now leads Madrid on head-to-head with the city rivals level on 70 points. Barcelona is on 69 points.
"Right up until the last game this league is wide open," Ancelotti said. "Any of these last nine games can prove decisive."
The high pace of play and buzzing atmosphere inside the Santiago Bernabeu Stadium left little doubt this was a "clasico" with much at stake.
Messi spotted Iniesta's run down the left side seven minutes in and slid a perfect ball clear into the area for him to lift into the top of goal to kickstart the memorable match.
Madrid winger Angel Di Maria troubled right back Dani Alves throughout, especially when he twice set up Benzema with crosses from the left side, with the France striker nodding home the first in the 20th before controlling the second to smash a right-footed volley beyond Victor Valdes. The goalkeeper got a glove to Benzema's opener but couldn't keep it out.
The strengths and philosophies of each club were apparent as Barcelona looked to set the tempo through possession while Madrid always looked dangerous when breaking on the counter.
Madrid's defense nodded off when Neymar and Messi's hopeful combination came to fruition and the Argentina star could equalize before halftime, with Benzema left ruing a number of missed chances that could have given Madrid control.
Gareth Bale's speed provided problems for Barcelona down the right, but Ronaldo was equally troublesome along the left and he was tripped by Dani Alves after the break to set up the penalty for his league-leading 26th goal that put Madrid back on top. However, replays showed the contact had taken place just outside the penalty area.
But Barcelona replied when Ramos was shown a straight red for tangling with Neymar and Messi stepped to equalize again.
Benzema then came off as Madrid looked to defend the draw, with Barcelona patiently coming forward and Dani Alves sending a shot off the post in the 74th. Iniesta was then taken down by Xabi Alonso and Dani Carvajal in the area to set up the 84th-minute spot kick that Messi slotted home for his 21st goal of the season.
"You could say some of the decisions penalized us, but it doesn't change anything," Ancelotti said. "We're not happy because we lost an important opportunity, but that's OK. We just need an immediate reaction now."
Messi climbed to No. 2 on the Spanish league's all-time scoring list with 235 goals, passing Hugo Sanchez. He also became the leading scorer in "clasico" matches with 21 goals, bettering the mark of 18 he shared with Madrid great Alfredo di Stefano.
In other 29th-round games on Sunday, Sevilla beat Osasuna 2-1 and Valencia won 2-1 against Villarreal.
Follow Paul Logothetis on Twitter: www.twitter.com/PaulLogoAP