DENVER — With one dramatic swing, Nolan Arenado gave the Rockies a thrilling victory and finished off a rare feat at the plate.

Arenado completed the cycle with a three-run homer in the bottom of the ninth inning, and the Rockies stunned the Giants by rallying for a 7-5 win Sunday.

Arenado hit the first pitch he saw from All-Star closer Mark Melancon (1-2) into the left-field seats to cap a four-game sweep. The slugger was mobbed at home plate by teammates, with a frenzied sellout crowd chanting “MVP! MVP!”

“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 is the first player to complete the cycle by hitting a game-ending home run since teammate Carlos Gonzalez did it July 31, 2010, against the Cubs.

With the best record in the National League, the Rockies (46-26) have won five straight.

The Rockies 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 the Giants, who have lost six straight.

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.”