ST. LOUIS, Mo. — Mets righthander Zack Wheeler delivered his longest outing in more than a month, seemingly getting himself back on track just before the All-Star break. But it wasn’t enough to spare the Mets from a 4-1 loss to the Cardinals on Saturday.

Wheeler allowed two runs and eight hits in six innings, his longest start since going seven innings against the Rangers on June 7. With his fastball in the mid-90s and sharper command of his secondary pitches, he lowered his ERA to 4.86.

The outing ended a stretch in which he allowed 15 earned runs over three games, all without completing four innings. That span included a stint on the 10-day disabled list with biceps tendinitis.

“That’s what I sort of wanted going into this All-Star break was sort of getting back on track and finishing the first half strong,” said Wheeler, who is in his first season after two years away while recovering from Tommy John surgery.

The Cardinals’ Adam Wainwright used a flurry of sinkers and curveballs to hold the Mets (39-46) to one run in 6 2⁄3 innings. They lost for the fourth time in five games.

“He was locating his pitches,” Travis d’Arnaud said. “He mixed in his curveball, was able to throw it for strikes when he wanted to and threw it in the dirt when he wanted to. He was very effective.”

Jay Bruce did the only damage against Wainwright, blasting his 23rd homer of the season into the Cardinals’ bullpen in right-centerfield. But it wasn’t enough to carry the Mets, who got another quiet day from slumping slugger Yoenis Cespedes.

advertisement | advertise on newsday

In his last 43 at-bats, Cespedes has six hits, all singles. He hasn’t had an extra-base hit since June 23.

“He’s our run-producer,” manager Terry Collins said. “He’s in the middle of the lineup. We’ve got to get him going.”

Bruce’s homer cut the Mets’ deficit to 2-1 in the seventh inning, but the Cardinals got the run back against struggling reliever Fernando Salas in their half of the seventh.

Stephen Piscotty laced an RBI single to drive in rookie Paul DeJong, who has torched the Mets, going 7-for-8 with six extra-base hits in the series.

Still, Wheeler kept the Mets in the game, a step forward for the 27-year-old. One of his mechanical adjustments including ditching the over-the-top motion to begin his delivery that he adopted early in 2014. It led to better tempo and command, particularly of his secondary offerings.

Mets videos

“Honestly, I just didn’t know what to expect coming back, with arm troubles or command or whatever it may be,” Wheeler said. “I felt fine most of the time. Those past three games really got away from me. I was doing OK up until then. But I’m feeling comfortable.”

The Mets seem more comfortable, too. Wheeler’s rough stretch had prompted questions about whether he could withstand the rigors of a season. Even in spring training, the Mets raised the possibility of managing his innings. But Wheeler’s DL stint and his abbreviated starts have negated the need to artificially manage his workload in the second half. He’s on pace to reach about 140 innings.

“When we get out of the break, I think he’ll be ready to push forward,” Collins said. “How far? How long? We don’t know yet. But we think his arm has bounced back.”