Pujols mashed a slider from Johan Oveido 398 feet to left field in the fourth inning, his 22nd homer of the season.
In his first game against his former teammate, Oviedo became the 456th different pitcher Pujols has homered against. Pujols hadn't homered in a week since hitting Nos. 699 and 700 at Dodger Stadium last Friday.
``It was a good pitch to hit and I just put the best swing on the night on it,'' Pujols said. ``That was it. A 1-2 count, just not trying to do too much.''
The drive tied the game at 1-1. After a lengthy standing ovation, Pujols came out of the dugout and tipped his cap to the sellout crowd.
``It's pretty awesome,'' Pujols said. ``I didn't know it was going to be like this. It's pretty good just to be embraced like this. I mean this is what I've been getting all year long but today was extra special. It was a great night overall.''
Oviedo (4-3) allowed two runs on six hits while striking out four. The Cardinals traded him and infielder Malcom Nunez to the Pirates on Aug. 1. The deal brought starter Jose Quintana and reliever Chris Stratton to St. Louis.
Flaherty (2-1) gave up four hits, struck out six and walked two in his fifth start since returning from a right shoulder injury that sidelined him most of the season.
``I'm just getting more into a groove the more times (I) get out there. We're just continuing to execute pitches and it feels great,'' Flaherty said.
The right-hander improved to 9-1 with a 2.60 ERA in 14 career starts against the Pirates.
He was happy to be the beneficiary of Pujols' power.
``He's done it in a lot of my starts. I feel like every time I go out there he's going to hit one,'' Flaherty said. ``I get to see the ball come off the bat and hear everybody, so it's fun when he does that.''
Nolan Arenado put the Cardinals in front in the fifth inning with a single that dropped just in front of right fielder Jack Suwinski to score Brendan Donovan.
Ji Hwan Bae drove in the Pirates' only run with a bunt single past Flaherty to score Ben Gamel in the fourth.
Pirates manager Derek Shelton took a moment to appreciate Pujols' accomplishments.
``I think we're seeing one of the best hitters of our generation and he's had an unbelievable second half,'' Shelton said. ``You cannot make mistakes to him right now. We made the one mistake to him and he hit it out of the ballpark. What he's done over the course of his career and especially what he's done over the second half is extremely special.''
Ryan Helsley pitched a scoreless ninth for his 19th save in 23 opportunities.
The 42-year-old Pujols is fourth on baseball's home run list behind Barry Bonds (762), Hank Aaron (755) and Babe Ruth (714). He has said this is his last season.
Pujols' homer was his 55th against the Pirates, his third-most against any team, trailing Houston (70) and the Chicago Cubs (62).
Before the game, the slugger was recognized for hitting his 700th last week at Los Angeles. He was given a gold-plated, engraved bat by owner Bill DeWitt Jr., team president Bill DeWitt III and manager Oliver Marmol.
Pirates: INF/OF Tucupita Marcano, RHP Nick Mears and RHP Junior Fernandez were added to the taxi squad. INF Michael Chavis and OF Greg Allen cleared waivers and were outrighted to the minor leagues.
Cardinals: RHP Jordan Hicks (right arm fatigue/right neck spasm) threw off a mound Friday and if he responds well, he will do the same on Sunday. ... OF Tyler O'Neill (left hamstring strain) ran in the outfield and Marmol said he'd like to see O'Neill face live pitching before making a decision on whether to activate him for the playoffs.
RHP Luis Ortiz (0-1, 1.17 ERA) starts for Pittsburgh and LHP Jordan Montgomery (8-6, 3.50 ERA) goes for St. Louis as the series continues on Saturday.