The Cardinals had tied it up at 3-3 on a solo homer in the top of the eighth off Mark Melancon (1-0), but the Pirates quickly responded in the next half-inning.
With one out and pinch-runner Josh Harrison at first base, Marlon Byrd drew a walk from Carlos Martinez (0-1) and Alvarez followed by sending a ground single through the right side of the infield for a 4-3 lead.
Russell Martin then came up and scorched a line drive to left for another RBI.
Jason Grilli allowed a hit in the ninth but finished up with his first post-season save, putting the Pirates one win away from a berth in the National League Championship series.
Beltran finished 2-for-3 with three RBI for the NL Central champion Cardinals, who now must win two in a row against their division rivals to avoid elimination.
Swim Week Miami Beach 2014 [PHOTOS]