Lionel Messi blew the La Liga title race wide open when the Argentina forward netted a hat trick in a 4-3 comeback win for the champions at 10-man Real Madrid in an action-paced 'Clasico'.

Chasing a fifth title in six years, defeat for Barca at Real's Bernabeu stadium would have all but killed off their challenge but they came out swinging and took a seventh-minute lead through playmaker Andres Iniesta.

Real, looking to restore their three-point lead at the top and undefeated in 31 matches in all competitions, were reeling but hit back with a Karim Benzema double before Messi's first of the night, a close-range snap shot through a crowd of players to make it 2-2 at the break.

Cristiano Ronaldo put Real ahead from the penalty spot 10 minutes into the second half after he was tripped by Dani Alves and the match turned when home captain Sergio Ramos was sent off for felling Neymar when he was through on goal in the 63rd.

Messi clipped home the resulting penalty to level at 3-3 and struck the winner from the spot six minutes from time after Iniesta was knocked to the ground in the area.

The Real players were furious about both penalty decisions but Barca played a courageous game as they had promised and dominated possession, particularly after Ramos was dismissed, and thoroughly deserved the victory.

With nine games left, Real have 70 points, level with city neighbours Atletico Madrid and one ahead of third-placed Barca.

Atletico beat Betis

Earlier, Atletico beat 10-man Real Betis 2-0 to take three points which, in the wake of Real's loss, puts them joint top of La Liga.

The hard-fought contest was changed in the 55th minute when Betis' Bryan Rodriguez was shown a second yellow card after swiping at the ball with his hand.

Three minutes later, Atleti's Gabi Fernandez smashed in the first goal, a swerving drive 10m outside the area that evaded Betis goalkeeper Antonio Adan.

Diego Costa made it 2-0 in the 64th, his 23rd league goal and 31st in all competitions.

"We showed great calm knowing we only need to depend on ourselves in the title race, regardless of other results," Atletico coach Diego Simeone said.

Last-placed Betis are now nine points from safety.

Elsewhere, Sevilla beat Osasuna 2-1 for a fifth straight victory in their push for a Champions League place.

Villarreal's European hopes however took a hit in a 2-1 defeat at Valencia.