With the Pirates clinging to a 4-3 lead in the seventh, Neil Walker and Andrew McCutchen singled with one out off Fernando Rodriguez and moved up when Garrett Jones reached on first baseman Matt Downs' fielding error.
That set the stage for Alvarez, who sent a sharp grounder up the middle off Houston's David Carpenter, scoring Walker and McCutchen for a pair of much-needed insurance runs.
McKenry's fourth-inning double handed a 4-2 lead to the Pirates, who won for the seventh time in eight games clinched their four-game series at PNC Park.
Pittsburgh came into the contest tied with the Cincinnati Reds atop the National League Central. The Reds played the Los Angles Dodgers later Wednesday.
Kevin Correia (5-6) earned the victory, allowing three runs on six hits in a six-inning performance.
Joel Hanrahan racked up his 21st save despite yielding a solo homer to J.D. Martinez in the ninth.
Dallas Keuchel (1-1) was touched for four runs on seven hits through 5 2/3 frames for Houston, which dropped its seventh straight.