Angel Pagan belted a rare walk-off inside-the-park home run to push world champion San Francisco past the Colorado Rockies 6-5 in 10 innings on Saturday.
Troy Tulowitski's solo homer in the top of the 10th had given the Rockies a 5-4 lead but Pagan's blast found the right field wall and the angled bounce gave him and Brandon Crawford time to beat the relay throws for the winning runs.
The two-run effort meant Pagan became the first player to end the game with an inside-the-park homer since Rey Sanchez managed the feat for the Devil Rays in 2004.
The result means both sides are tied at the top of the National League West on 27-22 records, level with Arizona, who fell 10-4 to San Diego (22-26).
Elsewhere, Boston beat the Cleveland Indians for the second day running with the Red Sox prevailing 7-4 thanks to a big inning late in the game.
The home side scored four runs in the eighth to take the advantage and held on to notch up their 30th win of the year (30-20) and drop the Indians to 27-21.
The New York Yankees remain ahead of the Red Sox in the American League East after also claiming their 30th win.
The Yankees (30-18) won 4-3 against Tampa Bay (24-24) in 11 innings after Lyle Overbay sent a solo home run over the wall and clutch closer Mariano Riviera took care of business in the bottom of the inning.
Former Cy Young winner R.A. Dickey failed to maintain his recent good form as his Toronto Blue Jays went down 6-5 to the Baltimore Orioles.
Danny Valencia and Adam Jones both homered for Baltimore (27-22) as Dickey was charged with six runs on nine hits in 6 2/3 innings for the Blue Jays (20-29), ending his personal two-game winning streak.
The Los Angeles Angels' resurgence continues as they made it seven straight wins with a 7-0 thumping of Kansas City.
Josh Hamilton and Hank Conger hit home runs in the rout to get the Angels to 22-27, while the Royals dropped their fourth in a row to fall to 21-25.
Minnesota (19-27) snapped a 10-game losing streak with an upset 3-2 win over the Detroit Tigers (27-20).
Atlanta (30-18) finished off their suspended game against the New York Mets (17-29) with a 7-5 win before adding a 6-0 triumph in Saturday's game to remain in control of the National League East.
The struggling Los Angeles Dodgers (20-27) scored an upset 5-3 win over St Louis (31-17).