It was a rewarding victory for the Cardinals, who found out before the game that Jack Flaherty, their ace right-hander, will be sidelined for a while due to what manager Mike Shildt termed a "significant" oblique injury.
"Nobody hung their heads. We found a way to get it done. Grit is a high compliment for this team," Shildt said.
O'Neill led off the ninth with a single against Blake Treinen (1-2) and stole second base. He scored when Sosa hit a sharp grounder into left field. Dodgers third baseman Justin Turner was playing in near the infield grass and was unable to get a glove on the ball.
The Dodgers had a chance in the ninth after pinch-hitter Yoshi Tsutsugo drew a two-out walk and advanced to second on Cody Bellinger's single. Mookie Betts then lined a ball to the warning track in left, but O'Neill made a leaping grab to give Alex Reyes his 16th save.
"Those are just go get 'em plays, just full throttle," O'Neill said. "I got a good first step on it. I knew I had to go get it. It was either going to be at the track, at the wall or over the wall. That's where I was going. I was timing my jump and it all kind of lined up."
John Gant threw six shutout innings, but the right-hander did not factor in the decision after Matt Beaty's two-run homer in the seventh off Giovanny Gallegos (3-1) tied it.
Tommy Edman and Dylan Carlson each had two hits and made great defensive plays in the sixth. Edman made a leaping catch at second base to snag Max Muncy's line drive that had a hit probability of 91% according to MLB Statcast.
With runners on second and third, Carlson prevented Gavin Lux from tying the game when he made a sliding catch in center to end the inning.
"Seeing those guys work is a beautiful thing. What they do kind of allows us to go out there and throw with a little more confidence," Gant said of the St. Louis defense. "Not maybe make plays. They're gonna make plays."
Dodgers manager Dave Roberts, who saw his team drop to 7-13 in one-run games, said the Cardinals' defense definitely was the difference maker.
"It was remarkable. The line score doesn't tell the story of the at-bats we took. Across the board those guys made a lot of good plays," he said.
St. Louis began the game with three straight hits off starter David Price. Edman led off with a double, advanced to third on a single by Carlson and scored when Paul Goldschmidt lined a ball into the corner in left field for a ground-rule double.
The Cardinals tacked on another run in the second when Carlson ended Price's night with a two-out single to drive in José Rondón.
The Dodgers finally broke through in the seventh to tie it. Albert Pujols drew a one-out walk before being lifted for a pinch-runner. Beaty then drove Gallegos' slider over the wall in right for his second home run of the homestand.
Gant allowed four hits with three walks and four strikeouts. It was only the second no-decision for the right-hander in his last nine starts.
Price - who was used as an opener for the second time this season - allowed two runs and five hits in 1 2/3 innings with a walk and three strikeouts.
After Price exited, Joe Kelly, Phil Bickford, Nate Jones and Mitch White held the Cardinals to one hit in 5 1/3 innings before the Cardinals were able to get to Treinen in the ninth.
"Across the board I thought they did a really nice job," Roberts said.
Cardinals: OF Harrison Bader (right hairline rib fracture) has started some light throwing and swinging. He is eligible to come off the 10-day injured list on Friday, but Shildt isn't sure if Bader will be ready.
Dodgers: OF AJ Pollock (left hamstring strain) was 1 for 3 with a home run and played six innings for Class A Rancho Cucamonga. He is expected to accompany the Dodgers to Atlanta for the start of this weekend's series and come off the injured list. ... RHP Jimmy Nelson (right forearm inflammation) threw batting practice to Tsutsugo and could be activated by this weekend. Nelson has been on the IL since May 20.
Cardinals RHP Carlos Martínez (3-4, 4.22 ERA) carried a no-hitter into the seventh inning in his last start on May 27 at Arizona before Ketel Marte broke it up with a single. Dodgers RHP Walker Buehler (3-0, 2.66) is 2-0 with a 2.00 ERA in his past four starts.
Game-saving catch on Betts' deep fly seals Cardinals' win
Tyler O'Neill chases down a potential game-winning hit from Mookie Betts for the final out as the Cardinals hold off the Dodgers.