Argentina international Messi scored in the 36th minute with a soft header after Ajax failed to clear a free kick.
His 71st goal in the competition came after he linked with substitute Pedro in the 76th minute as Barcelona qualified for the last 16.
Bayern Munich, Paris St-Germain and Porto join Barca in the next round.
Messi has now surpassed Real Madrid’s Cristiano Ronaldo, who has 70, in the list of Champions League top scorers.
“Messi is without doubt the best player I’ve seen as a player and a coach,” said Barca manager Luis Enrique.
While it took Raul 142 Champions League outings to score his 71 goals, Messi’s appearance against Ajax was his 90th in the competition.
Ronaldo, who started and ended Real’s 1-0 win against Liverpool on Tuesday on 70 goals, has featured in the tournament 107 times.
Ajax, who are left to battle it out with Apoel Nicosia in Group F for third spot and a place in the Europa League, finished with 10 men against Barcelona after defender Joel Veltman was sent off for two yellow cards.
Elsewhere in Group F, Uruguay international striker Edinson Cavani found the net in the first minute as leaders Paris St-Germain overcame Apoel Nicosia 1-0 to advance.
Goals by Franck Ribery and Mario Gotze ensured Bayern Munichovercame Roma 2-0 to win Group E with two games to spare.
The Italians, who began the match with Francesco Totti, Gervinho and Miralem Pjanic on the bench, will be fighting with CSKA Moscow and Manchester City for second spot.
“I’d like to congratulate my players. I never expected to qualify after four games,” said Bayern manager Pep Guardiola.
However, Bayern’s victory came at a cost as left-back David Alaba injured medial knee ligaments and Guardiola expects him to miss the rest of the calendar year.
Nani, who is on loan from Manchester United, scored one as Chelsea’s Group G rivals Sporting Lisbon defeated Roberto Di Matteo’s Schalke 4-2.
Sporting’s Portuguese rivals Porto overcame Athletic Bilbao 2-0 to seal their place in the last 16, Jackson Martinez and Yacine Brahimi with the goals.
Also in Group H, Shakhtar Donetsk defeated BATE Borisov 5-0, Brazilian striker Luiz Adriano scoring a hat-trick to take his tally in this season’s competition to nine goals in four appearances.