Messi maintains Barca lead at summit
The World Player of the Year equalised with a penalty and settled the match in the last minute with his 29th league goal of the campaign, after Thiago Alcantara had put Barca 2-1 up in a nervous display at the Nou Camp.
Real had put them under pressure by easing through a match that had been expected to be far tougher, when Kaka scored two penalties and set up Cristiano Ronaldo for a third at sixth-placed Bilbao.
Leaders Barca moved on to 84 points with seven games left to play. Sevilla climbed to fifth with 46, one ahead of Bilbao, after Ivan Rakitic scored a 68th-minute equaliser for a 2-2 draw at Real Mallorca.
"Madrid are going to fight for this league until the end, until it is mathematically impossible because this is the way we have been educated," Real captain Iker Casillas told reporters.
Both sides rested players ahead of their Champions League quarter-final second legs next week, when Barca visit Shakhtar Donetsk on Tuesday with a 5-1 advantage and Real travel to play Tottenham Hotspur with a 4-0 lead.
On top of that, Jose Mourinho and Pep Guardiola will have been preparing for the first of four possible meetings between the Spanish giants in 18 days starting with next Saturday's league encounter.
Four days later, they have the King's Cup final in Valencia and they look likely to meet again in the two-legged Champions League semi-finals.
Barca struggled to create clear openings against a side they hammered 8-0 earlier in the season, despite their almost complete domination of possession.
They were caught out after 50 minutes when Almeria broke and Corona beat Juan Manuel Pinto in a one-on-one to silence the Nou Camp, but Barca quickly levelled.
David Villa, who came on for the injured Bojan Krkic in the first half, was brought down by the slightest of touches from goalkeeper Diego Alves as he raced into the area, and Messi netted from the spot.
Thiago headed in from a corner after 64 minutes and with Guardiola nervously prowling the touchline the tireless Messi pounced on an error to settle the match with almost the last kick.
"It was difficult because at this stage of the championship everyone is fighting for something," Barca midfielder Javier Mascherano told Spanish television.
"Almeria are fighting for survival, but we remained calm and quickly equalised after their goal. The important thing is to keep winning games and to keep our pursuers eight points behind us."
Real fielded an unfamiliar looking side at San Mames with the likes of Ronaldo, Mesut Ozil, Xabi Alonso and Ricardo Carvalho on the bench and Pepe playing in midfield.
"You could have had doubts seeing the starting XI but you can see Madrid has a good squad," Aitor Karanka two told a news conference as Mourinho once again left his number two to face the media.
"Pepe played a great game in midfield and Kaka was really impressive."
Bilbao mounted a typical aerial bombardment of the visitors' area but for all their pressure they created few chances and left themselves vulnerable to counter-attacks.
One such break led to goalkeeper Gorka Iraizoz upending Argentina winger Angel Di Maria in the area, and Kaka slotted away from the spot in the 14th minute.
Di Maria went down easily for a penalty after 54 minutes and Kaka outwitted Iraizoz again from the spot, before releasing substitute Ronaldo with a ball over the top.
The Portuguese cut back inside his marker with style to end local hopes of a comeback in the 70th minute, bagging his 28th league goal of the season.