It was the Argentina forward’s 230th La Liga goal, putting him only four short of former Real Madrid forward Hugo Sanchez, second on the all-time list, and closer to record marksman Telmo Zarra on 251.
Barca dominated possession as usual, but one of their weaknesses this season has been defending set-pieces and Almeria pulled a goal back when Angel Trujillo headed in from a corner in the 26th minute.
Almeria did well to keep Barca at bay until seven minutes from time when Messi headed against the bar at a corner and captain Carles Puyol volleyed in the rebound. Xavi bent in a fourth in the 89th minute.
Villarreal and Real Sociedad both lost ground on Athletic Bilbao.
Villarreal drew 1-1 at home to bottom side Real Betis Balompie, while Sociedad lost 1-0 at Sevilla.
Valencia slipped to ninth after they were beaten 1-0 at Rayo Vallecano de Madrid.