DENVER — The Colorado Rockies were six outs away from a sweep. They had a big lead, too.

And then just like that, it all unraveled.

Andrew Toles hit a grand slam with two outs in the ninth inning off Rockies closer Adam Ottavino, helping Los Angeles overcome a late six-run deficit in a 10-8 win on Wednesday night for a doubleheader split.

Colorado took two of three in the series against the NL West-leading Dodgers. It hardly felt like the case, though.

“We won the series — doesn’t feel like it,” Rockies manager Walt Weiss said. “We had that game in hand.”

This marks the fifth series the Rockies have captured from a first-place team in August. They’re the only team in the majors with a positive run differential (plus-24) and a losing mark (64-69).

Still, it was a win that slipped away.

“We needed to sweep that team this week. Everybody played good. I just let everybody down tonight,” Ottavino said. “Unacceptable performance.”

Trailing 8-2, the Dodgers scored three times in the eighth and added five more in the ninth. Toles capped the final inning with an opposite-field homer off Ottavino (0-1) for his first career slam.

Ottavino tried to start the pitch inside, but it drifted into the middle of the plate.

Luis Avilan (1-0) threw a scoreless eighth to earn the win. Kenley Jansen pitched the ninth for his 40th save, getting David Dahl on a called third strike to end it.

The Dodgers began their comeback in the eighth with an RBI double from Yasmani Grandal, an RBI single by Joc Pederson and a sacrifice fly by Howie Kendrick. Chase Utley nearly brought in more, sending a two-out grounder up the middle with two on, but DJ LeMahieu ranged to his right, snared the ball and threw Utley out by a step to end the threat.

Los Angeles scored once in the ninth on an RBI single from Josh Reddick and then loaded the bases with two outs, setting the stage for Toles.

Starter Jeff Hoffman allowed two runs and was in line for his first big league win before the bullpen had a meltdown.

Stephen Cardullo did most of the early damage — on his 29th birthday, no less — with a grand slam during a five-run first inning off Bud Norris, who got the last-minute start with Rich Hill bothered by a blister. Cardullo also hit his first big league homer as a pinch-hitter in Game 1.

“Honestly, hitting two home runs on my birthday is definitely special,” Cardullo said. “Unfortunately, we lost tonight.”

In the opening game, left-hander Tyler Anderson (5-5) threw 6 1/3 stellar innings as the Rockies cruised to a 7-0 win for their first home shutout this season.

The doubleheader was necessitated by a rainout Tuesday.

Cristhian Adames turned in quite a doubleheader with six hits, including two triples. LeMahieu finished the day 3 for 8 to run his average to an NL-leading .345.

Nolan Arenado hit a two-run homer and finished with 36 RBIs for the month. It’s the most by a Rockies player for August, passing the mark of 33 set by Andres Galarraga in 1996.

“We’ve got an off day tomorrow and we’ve got a little extra time to recover from this one,” Weiss said. “We’ve been playing real well. It’s a shame we lost.”

TRAINER’S ROOM

Rockies: 1B Mark Reynolds (broken bone in left hand) was activated off the 15-day disabled list and entered both games as a defensive replacement. To make room, INF Daniel Descalso was put on the paternity list. … RHP Tyler Chatwood (back strain) will start Saturday.

UP NEXT

Rockies: Following a rest day, Colorado faces Arizona for three games. Lefty Jorge De La Rosa (8-7) starts Friday.