Messi's scoring display was a fitting farewell for the coach who helped the Argentina forward become the world's best player and forged Barcelona into one of the best teams to have played football.
After scoring his Spanish league-record 50th goal late on, Messi went to the sideline to embrace Guardiola, who is leaving after 13 titles in four seasons.
The only other player to have scored 70 goals in a first-division season was Archie Stark of Bethlehem Steel in the American Soccer League in 1924-25.
Real Madrid, which clinched the league title in the last round, won 2-1 at Granada thanks to Cristiano Ronaldo's 45th league goal and David Cortes' own goal in stoppage time.
“Life has given me this gift during the past five years of being able to live with these players and enjoy this spectacle,” Guardiola told the packed stands following his 97th win in 118 home games.
“I have been the privileged one, to feel so loved and admired during all these years. Many thanks to all, above all to those who I have worked with every day.”
Guardiola will coach Barcelona's last league game at Real Betis before having a chance at a 14th piece of silverware in the Copa del Rey final against Athletic Bilbao. Guardiola's assistant Tito Vilanova will then take over.
The stands were full of posters and signs in Guardiola's honor and a banner saying “Thanks Pep” hung on the outside of the stadium to greet the departing manager on arrival.
When Guardiola came out of the tunnel he was met by another enormous banner saying “We love you Pep!” and chants from the 89,044 fans.
Messi put Barcelona in front in the 12th with a free kick, his curling delivery slightly grazing the defensive wall before finding the side of the net.
Barcelona's all-time leading scorer made it 2-0 in the 64th when Cristian Gomez handled a ball he had tried to flip by the defender. Messi, who missed a critical penalty in Barcelona's elimination by Chelsea from the Champions League, stroked an unreachable strike off the inside of the post and into the back of the net.
“Messi deservedly captured all the spotlights tonight,” Guardiola said. “I hope that in the future he continues to play as well. He undoubtedly helped me a lot as a coach.”
With the result beyond doubt, the game turned into a party for the Catalan club, and it ended with a homage to its most successful manager ever.
Messi added another by racing onto a long pass and firing a left-footed shot by the goalkeeper in the 75th, and he scored another penalty in the 80th.
This is the second time Guardiola has said goodbye to Barcelona. But his exit in 2001 after 11 seasons as a midfielder was not given special treatment from his boyhood club.
The contrast with now could not have been starker.
After the final whistle the club played a video in Guardiola's honor with the highlights of his coaching career, which included two Champions League titles and three Spanish league crowns. The former Barcelona midfielder then danced with his team in a circle in the middle of the pitch.
“Know that I will miss you all,” Guardiola told the crowd. “But I am leaving you all in the good hands of these players.”
In Granada, Madrid fell behind early after Franco Jara robbed Marcelo of the ball, charged up the field and shot under the legs of Madrid goalkeeper Adan Garrido, playing in place of Iker Casillas.
But Ronaldo converted a penalty in the 82nd and Cortes turned a cross into his own goal three minutes into injury time.
Madrid has 97 points and can set a league record with 100 points with a win over Mallorca in the final round.
Elsewhere, Valencia beat Villarreal 1-0 to clinch third place for the third straight season and automatically qualify for next season's Champions league.
Atletico Madrid beat fourth-place Malaga 2-1, giving it a shot at overtaking the Costa del Sol club in the final round and claiming Spain's last Champions League playoff spot.
The race to avoid the drop could not be tighter after Zaragoza downed the already-relegated Racing Santander 2-1 and Sporting Gijon beat Betis 1-0. Second-to-last place Sporting has 37 points. Zaragoza and Rayo Vallecano both have 40, while Villarreal has 41 and Granada 42.
Also, it was: Mallorca 1, Levante 0; Athletic Bilbao 0, Getafe 0; Sevilla 5, Rayo Vallecano 2; and Osasuna 1, Real Sociedad 0.