Messi had been one short of the record for over a month but finally matched Telmo Zarra's 251 league goals with a fantastic free-kick, before adding two more after the break.
The 27-year-old Argentine has scored 368 goals for Barcelona, the only senior club he has ever played for.
Lionel Messi is La Liga's all-time leading goalscorer after scoring a hat-trick in Saturday's 5-1 thrashing of Sevilla.