SAN FRANCISCO — The up-and-down Giants are going down to the wire in a bid to keep their even-year magic going.

With three games left, manager Bruce Bochy's ballclub is sandwiched between the Mets and Cardinals in the race for the two NL wild-card spots with two games separating the three teams.

It's not exactly how Bochy envisioned it, not after the Giants went into the All-Star break with the best record in the majors. Given the alternative, however, San Francisco's skipper certainly isn't complaining.

"We certainly wish we were in a better position but you don't stop fighting," Bochy said following San Francisco's 7-2 victory over the Colorado Rockies on Thursday night. "It is what it is as far as our situation that we created. We know that."

The Giants — who won the World Series in 2010, '12 and '14 — are one game behind the idle Mets and one game ahead of St. Louis. The Cardinals beat Cincinnati on Thursday.

San Francisco hosts the Los Angeles Dodgers beginning Friday, the Cardinals play Pittsburgh at home and the Mets close out the regular season in Philadelphia.

"I don't know what's going to happen but they'll keep fighting and we'll see what happens," Bochy said.

Johnny Cueto pitched seven uneven innings for his 18th win to help set up the wild race to the finish.

Cueto (18-5) overcame a shaky start in his first appearance since being sidelined more than a week with a groin strain. The All-Star right-hander matched his season high of 11 strikeouts, allowed two runs, nine hits and walked one to beat the Colorado for the third time this season.

"After we took the lead I just got focused on what I needed to do," Cueto said through an interpreter, adding that he's open to pitching in relief against the Dodgers if needed. "I'm ready. The last game is on Sunday and if they give me the ball I'll take (it)."

Conor Gillaspie, Angel Pagan and Brandon Crawford had two hits apiece to help the Giants bounce back after getting shut out a night earlier.

Nolan Arenado had two hits and an RBI for Colorado, which was eliminated from playoff contention over the weekend and has dropped eight of 10.

"(Cueto) found his groove and he was doing his thing," Rockies manager Walt Weiss said. "Once he gets rolling he's one of those top-of-the-rotation guys that can be tough to get to."

On a night when St. Louis rallied to win on a walkoff hit in the ninth, San Francisco staged its own comeback.

Arenado hit an RBI double in the first and scored on David Dahl's triple to put the Rockies up 2-0.

The Giants tied it with two runs in the fourth, then went ahead in the sixth with help from Colorado's defence. The Rockies committed two errors, including a wild throw by third baseman Arenado on Cueto's one-out bunt single that allowed two runs to score.

Colorado starter Jon Gray (10-10) allowed five runs over 5 1-3 innings and left shortly after he appeared to get hit in the right ankle by Crawford's line drive in the sixth.

"It hurt pretty bad but I'll be all right. Nothing serious," Gray said.

TAKING NO CHANCES

Bochy used four relievers to record the final six outs. One-time closer Santiago Casilla was not among them. Instead, Sergio Romo pitched the ninth and retired Charles Blackmon on a fly ball to end it. "You're in a situation where you have to win now," Bochy said.

TRAINER'S ROOM

Giants: INF Eduardo Nunez is making slight progress from a mild hamstring strain but could still miss the wild-card round of the playoffs if San Francisco makes it that far. Nunez has not played since Sept. 25.

UP NEXT

Rockies: RHP Chad Bettis (13-8) makes his final start of the season against Milwaukee on Friday. Seven of Bettis' wins this season have come at Coors Field.

Giants: LHP Madison Bumgarner (14-9) pitches the series opener against the Dodgers on Friday night. Bumgarner is winless over his previous four starts and has a 4.21 ERA during that span.