Carpenter drew a standing ovation in his first visit back to the city where he played 11 seasons, then had two hits. Aaron Judge and Josh Donaldson also had two hits each for the Yankees, and Donaldson drove in two while New York built a 3-2 lead.
''A lot of emotions,'' Carpenter said. ''I spent a lot of time here. I have a lot of great memories here. It was definitely a special moment.''
The Cardinals erased the deficit in the eighth. Nolan Arenado hit a one-out single, and Tyler O'Nell worked a two-out walk on a full count.
''Hats off to Nolan and T.O. to get on base to give me the opportunity,'' DeJong said. ''Earlier in the year, I might have dreaded an opportunity like that, but now I'm thankful for an opportunity like that.''
DeJong, playing his sixth game since being recalled from Triple-A, doubled to right against All-Star Clay Holmes (5-3) to score both runners.
All four of DeJong's hits since he has returned have been for extra bases.
''I'm really happy to be back here and contributing,'' DeJong said. ''I'm happy I'm getting the chance.''
Rookie Andre Pallente (5-4) threw four scoreless innings in relief. He gave up three hits with two strikeouts. He threw 65 pitches.
Ryan Helsley earned his 10th save by pitching the ninth. He retired Carpenter on a groundout to end the game on a close play at first.
The Cardinals, who had just four hits in the game, have won a season-high five straight. St. Louis extended its home winning streak to six games.
The Yankees have lost a season-high three games. They lost for the fourth time when leading after seven innings.
''It's not easy for us right now,'' manager Aaron Boone said. ''We had a lot of hits. I thought we hit the ball really well. They made some really good plays. I thought we had a lot of quality at-bats up and down, but we couldn't get that back breaker to put it away.''
New York starter Nestor Cortes threw 5 1/3 innings before being lifted after a walk. Cortes, who pitched in the All-Star Game last month, allowed one hit and two runs. He walked four with four strikeouts.
Carpenter, a three-time All-Star with the Cardinals, received a 45-second ovation before his first at-bat. He tipped his cap to the fans and then to the Cardinals' dugout. Carpenter batted .262 with 155 homers and 576 RBIs with St. Louis from 2011-21.
''You could make a case they're the New York Yankees of the National League,'' Carpenter said in a pregame news conference about the Cardinals. ''Combine that with just the history of the organization and what it means to put on that jersey, well, it's a pretty cool place.''
Yankees: Claimed RHP Luke Bard off waivers from the Tampa Bay Rays and assigned him to Triple-A Scranton/Wilkes-Barre. Bard, 31, went 1-1 with a 1.93 ERA in eight relief appearances for the Rays this season.
Cardinals: Claimed INF Kramer Robertson off waivers from the New York Mets and optioned him to Triple-A Memphis. ... Transferred RHP Drew VerHagen (right hip impingement) from the 15-day to the 60-day injured list. ... RHP James Naile optioned to Triple-A Memphis.
Yankees: 1B Anthony Rizzo (lower back tightness) was scratched from the starting lineup just before the game began. He missed four games last month with the same issue. Rizzo has 27 homers this year.
Cardinals: RHP Jack Flaherty (shoulder) is scheduled to throw a bullpen session Saturday with pitching coach Mike Maddux watching. If all goes well, he could be cleared for a minor league rehab assignment next week. ... OF Juan Yepez (forearm strain) has begun swinging and throwing. A rehab assignment in Triple-A remains a possibility.
Yankees: Domingo German (1-1, 6.38) started last Monday against Seattle and earned his first win of the season when he pitched 5 1/3 innings. He missed the first 93 games of the season with right shoulder impingement syndrome. He starts Saturday against St. Louis.
Cardinals: Jordan Montgomery (3-3, 3.69) faces his ex-teammates five days after being traded to St. Louis for center fielder Harrison Bader.
More AP MLB: https://apnews.com/MLB and https://twitter.com/AP-Sports
Copyright 2022 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.