The Pirates moved within six games of the first-place Cardinals in the NL Central with their 12th victory in 18 games.
St. Louis, which won the first two in the series, has won the last seven sets between the teams at Busch Stadium.
Alvarez had three hits as the Pirates held on. The Cardinals closed their seven-run deficit to 7-5 in the seventh.
Francisco Liriano (8-6) pitched six innings.
Lance Lynn (9-7) got just two outs in the shortest of his 119 career starts.