Sevilla keeps pace
Earlier, third-placed Sevilla stayed just one point behind Real and Barca with a 1-0 victory over Leganes.
Julen Lopetegui's side extended their unbeaten run in all competitions to 10 matches as Brazilian centre-back Diego Carlos bundled in a 63rd-minute winner at the Estadio Ramon Sanchez Pizjuan.
Real wins
Archrivals Real Madrid had a brief stay at the top after they grounded out a tough 2-1 victory away at Alaves.
After Sergio Ramos put Real in front, he conceded a penalty to allow Lucas Perez to equalise. Later, Dani Carvajal turned the unlikely hero by netting the winner.
Messi magic
At the Wanda Metropolitano, an even contest looked destined to finish goalless before Messi scored late to deliver a major boost to Barcelona's La Liga title hopes.
Messi scored his 12th goal of the season and sixth in his last five games. He has 25 in 27 now against Atletico but this was his first at the Wanda Metropolitano.
Griezmann booed
Antoine Griezmann was whistled on his return to his former club, whom he left to join Barcelona in the close season, while rats were dropped on the plaque that still bears his name outside the stadium.
Barcelona were fortunate not to be reduced to 10 men in the second half when Gerard Pique escaped a second yellow card for a late challenge on Alvaro Morata.