It took 6 hours, 7 minutes to finish. Both teams scored a run in the 17th, and each club used eight pitchers.
Alvarez hit his 23rd homer, a solo shot off Barret Browning (1-3). Andrew McCutchen added a two-run single later in the inning.
Wandy Rodriguez (8-12), who was set to start for the Pirates on Monday night at San Diego, got the win with two scoreless innings of relief.
About 9,000 fans from the original crowd of more than 43,000 stayed until the end. This was the longest game by innings in the big leagues this year. At 6:07, it tied for the longest by time, matching a game between Baltimore and Boston on May 6.
Each team had played a marathon in recent years. St. Louis went 20 innings against the Mets on April 17, 2010, and Pittsburgh played 19 innings at Atlanta on July 26, 2011.
DIAMONDBACKS 8, ASTROS 1
HOUSTON (AP) — The Houston Astros lost in their first game under interim manager Tony DeFrancesco as Aaron Hill homered twice to give the Arizona Diamondbacks an 8-1 win and a sweep.
DeFrancesco was the manager at Triple-A Oklahoma City before being promoted. The Astros, with the worst record in the majors, fired Brad Mills late Saturday night.
Houston dropped its fourth straight and fell to 7-33 in its last 40 games.
Arizona won its ninth in a row against the Astros.
Hill, who connected for a three-run homer on Saturday night, kept going deep. He led off a five-run fourth with a shot off Armando Galarraga (0-4) and added another solo homer in the eighth. Hill also doubled.
Ian Kennedy (11-10) went six innings.
NATIONALS 5, METS 2
WASHINGTON (AP) — Bryce Harper homered and tripled, and Danny Espinosa also homered to lift the Washington Nationals over the New York Mets.
Gio Gonzalez (16-6) pitched into the sixth inning, allowing one run and seven hits. Tyler Clippard pitched a perfect ninth for his 27th save in 31 chances.
Jeremy Hefner (2-5) took the loss as the Mets fell for the ninth time in 13 games.
DODGERS 5, BRAVES 0
ATLANTA (AP) — Chad Billingsley combined with two relievers on a three-hitter to win his sixth straight start, Luis Cruz homered for the second game in a row and the Los Angeles Dodgers beat Atlanta.
Mark Ellis drove in four runs, three with a bases-loaded double in the ninth.
Billingsley (10-9) gave up three hits in seven innings, striking out four and walking two. He is 6-0 since the All-Star break after losing five straight. He reached 10 wins for the sixth straight season.
Cruz homered deep into the left-field seats in the fifth off Mike Minor (6-10) for a 1-0 lead.
REDS 5, CUBS 4
CINCINNATI (AP) — Xavier Paul led off the ninth inning with a pinch-hit triple and Ryan Hanigan followed with a single, lifting the Cincinnati Reds over the Chicago Cubs.
Paul lined the first pitch from Shawn Camp (3-6) over first base into the right-field corner. Hanigan hit the next pitch to left-centre over the drawn-in Chicago outfield.
The NL Central-leading Reds took three out of four from the Cubs and finished a 5-2 homestand.
Aroldis Chapman (5-4) struck out two in the ninth. Brett Jackson doubled with one out, but was caught trying to steal third.
PADRES 7, GIANTS 1
SAN DIEGO (AP) — Clayton Richard pitched eight sparkling innings, Cameron Maybin drove in three runs and the San Diego Padres snapped a five-game losing streak by beating San Francisco.
The Giants dropped out of first in the NL West and trail the Dodgers by a half-game heading into their big three-game series in Los Angeles. Madison Bumgarner is scheduled to face Dodgers ace Clayton Kershaw in the opener on Monday night.
Richard (10-12) was 0-3 with a 7.64 ERA in his three previous starts against San Francisco this season.
Maybin tied his career high with four hits, including a two-run single in the first inning when the Padres scored three times against Ryan Vogelsong (10-7).
ROCKIES 3, MARLINS 2
DENVER (AP) — Jordan Pacheco homered among his three hits as the banged-up Colorado Rockies slowed down Giancarlo Stanton and beat Miami.
Stanton went homerless for the first time in seven games at Coors Field. On Saturday night, he became the first player in big league history to homer in his first six games in a particular park, the Marlins said in citing the Elias Sports Bureau.
Stanton drew two intentional walks and went 0 for 2 in the series finale.
Rockies outfielder Eric Young Jr. left after one inning with a strain in his left ribcage and shortstop Josh Rutledge exited in the fifth with tightness in his left thigh.
Adam Ottavino (5-1) tossed three scoreless innings for the win and Rafael Betancourt pitched the ninth for his 23rd save.
Josh Johnson (7-10) lost his third consecutive start.
PHILLIES 8, BREWERS 0
MILWAUKEE (AP) — Kyle Kendrick pitched three-hit ball for eight innings and the Philadelphia Phillies beat Milwaukee after waiting out a rare rain delay at Miller Park.
The game was held up for 7 minutes when showers popped up in the first inning with the retractable roof still open. It takes about 10 minutes for the roof to fully shut, and the game was delayed with the Brewers batting in the bottom half when the rain became harder. Most of the Phillies stayed on the field.
Kendrick (6-9) struck out seven and walked one. In his previous start, he threw seven impressive innings and beat Miami 1-0.
Domonic Brown drove in four runs and scored twice. Michael Martinez, who began the day hitting .130, homered off Randy Wolf (3-10).