The Giants scored twice in the ninth to tie the game, with Fred Lewis singling home Rajai Davis to send it into extra innings. Ray Durham led off the inning with a double and scored when Rich Aurilia singled into left field.
Ryan Ludwick hit a two-run homer in the top of the ninth off Brad Hennessey as the Cardinals scored eight runs on nine hits after Cain's no-hit bid was broken up by Albert Pujols' double to lead off the seventh.
"It's definitely something I think about," Cain said of his no-hit bid. "It's out there. Maybe somebody else can avoid thinking about it, but I couldn't. I don't worry about keeping the no-hitter, I worry about getting guys out."
Cain delivered the Giants' fifth consecutive quality start, though the Giants have lost the last two.
"He did everything," Giants manager Bruce Bochy said. "He pitched great, he hit the home run and we had a five-run lead. We let it slip away. That's one we can't let get away for him, and we did, we let it get away."
Chris Duncan singled home the go-ahead run in the top of the 10th after Erick Threets (0-1) walked the first batter he faced and hit the next one.
"The walk and hit batter came back to haunt us," Bochy said. "We came back to tie it in the ninth and had the winning run on second base. It wasn't enough."
Giants outfielder John Bowker made his Major League debut a memorable one with two hits, including a three-run home run. Cain also hit a home run, the third of his career.
"I knew I hit it pretty good, but since I haven't hit one here, I didn't know for sure," Bowker said. "It's a big yard."
Bowker was recalled from Triple-A Fresno late Friday night. The Sacramento native singled in his first Major League at-bat and then became the eighth San Francisco Giant to hit a home run in his first game. Eliezer Alfonzo was the last to accomplish the feat, with a home run on June 3, 2006, in Yankee Stadium.
"To get the first hit out of the way was nice," said Bowker, who was called out for a curtain call after his home run. "To hear the crowd in the background was icing on the cake."
The Giants scored their first five runs in the sixth, with Bengie Molina adding an RBI single to the power production.
Adam Kennedy and Rico Washington each drove in a run against Cain in the seventh, and then a solo home run from Duncan and a two-run shot from Rick Ankiel against Tyler Walker in the eighth tied it.