"It's probably one of the best moments in my career," Arenado said. "I've hit some big homers but by far the best, obviously, for the cycle. I've never done it. I feel like I've been kind of close but I've always needed a triple and I ain't getting that. Today is a great day."
Arenado became the fifth player in major league history to complete the cycle by hitting a game-ending home run, according to the Elias Sports Bureau. The last to accomplish the feat was teammate Carlos Gonzalez, who did it on July 31, 2010, against the Chicago Cubs.
"I remember watching Carlos do that," Arenado said. "Now I know how he feels."
With the best record in the National League, the surprising Rockies (46-26) have won five straight overall and nine in a row against the Giants. They are 20 games above .500 for the first time since 2009.
"The fans and the people of Denver are starting to get a hint that we're for real," Arenado said.
Colorado had a 3-2 lead in the top of the ninth but gave up three runs before scoring four in the bottom half.
Pinch-hitter Hunter Pence connected on a go-ahead homer for last-place San Francisco, which has dropped six consecutive games and nine of 11.
Melancon retired his first batter, but three singles produced a run and brought up Arenado, who tripled in the first, singled in the fourth and had an RBI double in the sixth. He hit a 91 mph fastball for his 15th homer and first career cycle.
"I was ready first pitch and I was just trying to get the ball to the outfield, really," Arenado said. "Luckily, I got a pitch middle-in and I was able to do some damage with it."
It was his second game-ending homer in the majors and the eighth cycle in club history.
Melancon has not recorded a save since May 27.
"This was as tough a one as we've had," Giants manager Bruce Bochy said. "I mean, look at those hits (in the ninth). A blooper into center field, another one that we couldn't quite get to and an eight-hopper to center. The other guy came through, but (Melancon) should have fared a lot better."
Carlos Estevez (4-0), called up from the minors before the game, struck out one batter in the ninth for the win.
Trevor Story and Pat Valaika went deep in the seventh to give Colorado a 3-2 edge after Brandon Crawford's two-run homer in the fifth put the Giants ahead.
Rockies reliever Jake McGee came on in the ninth but issued a one-out walk to Gorkys Hernandez. Pence hit an 0-1 fastball into the left-center seats for his first career pinch-hit homer, and Crawford added an RBI single later in the inning.