McAvoy also had a goal and an assist, Morgan Geekie scored, and Jeremy Swayman made 20 saves for the Bruins, who are 4-1-1 their past six games.
"We stayed patient, honestly," Pastrnak said. "I felt good after two. Even though we didn't score, you could feel that there was the belief, and we were really one bounce away because there was some chances. The goalie [Binnington] played really well on the other end. The mindset going into the third was good."
Brayden Schenn and Oskar Sundqvist scored, and Binnington made 27 saves for the Blues (7-9-0), have lost three in a row and ended a season-long five-game homestand 2-3-0.
St. Louis was 5-0-0 when leading after two periods.
"We just stopped making plays, stopped putting pucks on the tape and let them come at us, played in our end the whole period," Schenn said. "Five-on-five just in general, we're not generating enough to tilt the ice. I'm not saying score goals, just to put them on their heels a little bit. We've got to find a way. Special was good tonight, they gave us a chance to win the hockey game. Our goalie was good. We just sat back in the third and quit making some plays. Not plays, just passes on the tape. They came at us, and we're on our heels the whole third."
Geekie made it 2-1 at 4:53 of the third period, scoring with a one-timer off a 2-on-1 with Pastrnak after Colton Parayko lost the puck at the offensive blue line.
Geekie had been a healthy scratch the past three games.
"Obviously, it was a big goal in the game," Geekie said. "I kind of felt like we were all over it tonight and it was nice to see one go in."
McAvoy tied it 2-2 at 9:15 on a slap slot from the point.