For nearly half the game Thursday night, it looked as if a month of rest and rehabilitation had done wonders for Braves pitcher Paul Maholm.

But after allowing no hits through three innings and being handed a 2-1 lead on Justin Upton’s two-run homer in the fifth, Maholm quickly gave it all back — and then some — during a 6-2 loss against the Cardinals that opened a four-game series at Busch Stadium.

Maholm (9-10) walked No. 8 hitter Pete Kozma with one out in the fifth, then surrendered three consecutive two-out, run-scoring doubles by Matt Carpenter, Carlos Beltran and Matt Holliday, giving the Cardinals a lead they wouldn’t relinquish.

“I felt good the first four innings,” Maholm said. “Till the fifth, I made my pitches. I still put myself in position to get out of (the fifth) with two outs and two strikes, and nobody had scored yet. For three hitters, I made three bad pitches.

The Braves have lost five of 11 since a 14-game winning streak. They still hold a commanding 13 1/2-game lead over second-place Washington in the National League East, but the Braves’ margin over the surging Dodgers for the best record in the National League was reduced to 1 1/2 games.

The team with the best record can assure itself of home-field advantage through the NL playoffs.

The Braves lost their first game since right fielder Jason Heyward was struck in the face by a fastball Wednesday at New York, which broke his jaw in two places and could sideline the leadoff hitter for at least the rest of the regular season.

“That’s took a toll on us yesterday, losing Jason,” Upton said. “It’s rough, but we’ll get back on our feet and be ready to go.”

In losing his fourth consecutive start, Maholm was charged with five hits, five runs (four earned) and three walks in 5 1/3 innings, the last run on his ledger scoring on a wild pitch by reliever Luis Ayala. A throwing error by shortstop Andrelton Simmons caused the sixth inning run to be unearned.

“For the first time in over a month, I think he did a nice job,” Braves manager Fredi Gonzalez said of Maholm. “It’s a tough lineup to navigate, especially (for a left-hander) with all those really good right-handed hitters they’ve got. But I thought he did a nice job, kept us in the ballgame, gave us an opportunity to win the game.

“He mixed his pitches well, he changed speeds. I didn’t see any rust. Other than the third time through the lineup.”

Upton’s eighth homer of August was a no-doubt-about-it, first-pitch drive to the left-field seats with one out, after Maholm had started the inning with a single. All but four of Upton’s 24 home runs have come in April and August, and his homer off Cardinals starter Joe Kelly (5-3) was the first off the right-hander in his past seven starts.

“I’m seeing the ball pretty good, I’m getting pretty good pitches,” Upton said. “That’s about it.”

Maholm made his first start since leaving a July 20 game against the White Sox with a sprained and bruised left wrist, which he initially hurt while batting in a game 10 days earlier. He made one rehab start before being plugged back into the rotation Thursday against a team he’s struggled against more often than not (4-8 in 19 career starts vs. the Cardinals).

After posting a 3.38 ERA in his first 10 starts this season, Maholm has a 5.63 ERA in his past 11 starts. He’s 0-4 with a 9.16 ERA in his past four.

Continuing his season trend, he fell to 4-8 with a 6.08 ERA in 14 road starts, compared with 5-2 with a 1.97 ERA in seven home starts.

“Believe me, I know (the road results) suck,” he said. “I’ve made two-thirds of my starts on the road. I don’t know. I guess it’s just the draw that I got. I’ve got to figure it out on the road and got to make better pitches and manage the lineup, not put yourself in situations that can hurt you.”

Maholm had some encouraging early innings Thursday, issuing a pair of two-out walks in the first inning but getting David Freese to ground out without any damage. He retired the side in order in the next two innings before Holliday led off the fourth with a double, the first hit for St. Louis.

Holliday scored on Freese’s ground out for a 1-0 lead, but Upton answered with his team-high 24th homer in the fifth.

After a stretch in which Maholm retired 12 of 14 batters, the bottom fell out in the fifth inning with the three doubles by Cardinals’ Nos. 1-3 hitters. Carpenter and Beltran each doubled with two strikes, and Holliday’s double to the left-field corner capped a three-run inning for a 4-2 lead.

He rued the Kozma walk.

“That, and getting in situations where three straight guys I could have put them away,” Maholm said. “They put good swings on it; obviously I didn’t make the pitches I wanted to, but they’re a good lineup. It’s a challenge to go through. The first four innings I made my pitches, then I got to where I missed, and they take advantage of it.”