From a pitching standpoint, the White Sox’ 13-9 victory Wednesday against the Astros at Guaranteed Rate Field wasn’t pretty.

The teams combined for 30 hits (15 apiece), and the Sox scored a season-high run total.

After Sox starting pitchers had allowed only six earned runs in 40‰ innings before this game, Ross Detwiler allowed four in 4‰ innings.

But the offense bailed the team out this time.

James McCann’s go-ahead grand slam in the eighth inning gave the Sox (54-65) the boost they needed to capture the series against the top team in the American League West.

Manager Rick Renteria said it was one of the most exciting victories of the season.

“Both teams didn’t quit,” Renteria said. “I know there were a lot of ups and downs. I know we gave up a few runs; we gave up the lead. But to highlight that by Alex [Colome] coming in and just stopping them there. And the two-out, two-strike granny, you can’t write it any better than that for a young man who has been grinding and putting in a pretty good season for himself and helping us in the organization.”

McCann’s blast was his fourth career grand slam. He said he was trying to get Astros right-hander Ryan Pressly’s pitches up.

“The emotions that are going through your body, there’s really nothing that compares to it,” McCann said. “It’s something that we all dream of as little boys, and to have it come to fruition as a grown man, it makes you a kid again.”

One inning before McCann’s slam, Eloy Jimenez hit a 434-foot shot over the center-field wall. He became the 11th Sox rookie to hit 20 or more homers in a season.

“When you have these days, it’s really good because when one starts, you can keep going like today,” Jimenez said. “We do a really good job of not losing the focus on the game and just keep battling.”

The Astros (78-43) didn’t go away quietly, which is expected from one of the top teams in the majors. They erased multiple leads, including tying it at 9 on Jose Altuve’s two-run homer in the eighth inning.

After Evan Marshall and Josh Osich pitched in the eighth, Colome (4-2) stabilized the Sox on the mound, picking up the victory after striking out two and not allowing a hit in 1‰ innings.

“I’m more elated in the way that — even though we gave up the lead, and they ended up tying it with such a good lineup — we didn’t quit,” Renteria said. “They’ve been doing that all year. It may not go well for us, but these guys keep fighting, they keep playing. They want to have success; they want to be able to get it done.”

McCann said the Sox pulling out the win after blowing the lead shows the team’s fight and tenacity.

He recognizes the progress the team has made as it heads to Anaheim, California, for a four-game series against the Angels before closing out a seven-game trip against the Twins.

‘‘We very easily could have folded and given in to them and the talent they have over there,” McCann said. “But we kept fighting and kept pushing and never gave in, and that’s really good to see.”