Updated

Madrid, Spain (SportsNetwork.com) - Lionel Messi scored three goals, including two penalty kicks in the final 25 minutes, to help Barcelona claim a 4-3 comeback win at Real Madrid on Sunday in a pulsating Clasico encounter.

Madrid entered the contest four points clear of Barca and could have all but eliminated the Catalans from the title race with a win on Sunday.

And when Cristiano Ronaldo scored from the penalty spot in the 55th minute to put Madrid up 3-2 it looked like time was running out on Barca.

But Madrid's Sergio Ramos was sent off in the 63rd minute when he brought down Neymar inside the box, allowing Messi to score his second goal of the match before he completed his hat trick six minutes from time.

Madrid is now just one point clear of Barca at the top of the league while Atletico Madrid pulled level on 70 points with Real Madrid after notching a 2-0 win at Real Betis on Sunday with second-half goals from Gabi and Diego Costa.

Barca started brightly with Andres Iniesta scoring in the seventh minute after being set up by Messi, but Karim Benzema replied with two goals in four minutes to put Madrid in front as he converted crosses from Angel Di Maria on both occasions.

Messi leveled the contest at 2-2 a few minutes before halftime, but Ronaldo restored his team's lead in the 55th when he was tripped inside the penalty area by Dani Alves and scored on the subsequent spot kick.

However, the match was turned on its head in the 63rd when Ramos brought down Neymar as the last man, allowing Messi to score from the spot and leaving Real with 10 men.

Alves came close for Barca in the 74th with a shot that struck the post, but Madrid was unable to hang on for a point when Xabi Alonso tripped Iniesta inside the area with six minutes to play, giving Messi the chance to bury a clutch penalty kick that hauls his team right back into the title mix.

Villarreal fell 10 points back of a place in the top four after losing 2-1 at Valencia to a pair of goals from Javi Fuego, while Sevilla jumped into fifth place after notching a 2-1 win at Osasuna.