ST. LOUIS (AP) — Lance Berkman has agreed to a $12 million contract with St. Louis, giving the Cardinals a valuable bat for 2012.

The 35-year-old Berkman is completing a big comeback season with 31 home runs, 91 RBIs and a .300 average. The switch-hitter made his sixth All-Star team this summer, his first such honor since 2008.

The signing was announced Thursday, before a game against the New York Mets. The Cardinals had won 12 of 14 and were 1 1-2 games behind the Braves for the NL wild card.

Berkman said he’d been aware for a few days that the deal was done. Talks accelerated recently and Berkman pointed out he probably could have gotten a two-year deal for the amount he got from the Cardinals had he opted for free agency.

"Really, at no point was it ever contentious," Berkman said. "I think from the very beginning both sides really wanted to get something done and there was compromise on both ends, and we got it done."

Signing Berkman provides a potential backup plan for the Cardinals if Albert Pujols leaves as a free agent. The three-time NL MVP, who has played all 11 major league seasons with St. Louis, cut off negotiations on a new contract at the start of spring training.

"We don’t know what 2012 is going to look like for sure, but we do know Lance Berkman is going to be a part of it," general manager John Mozeliak said. "You just look at what Lance did for us and to go into this offseason with sort of the unknown just really wasn’t a comfortable thing for us."

Whatever happens with Pujols, Berkman said he was "committed" to the Cardinals.

"I’d love to see him come back here," Berkman said. "That would be a dream come true, for myself and for the organization, I’m sure, and for Cardinals fans, but unfortunately sometimes the economics of the game don’t allow things like that to happen.

"If something were to happen where he doesn’t come back, I still feel like we have a great team, but obviously any team would be better with Albert Pujols as a part of it."

The Cardinals began building last week when they signed pitcher Chris Carpenter to a $21 million, two-year deal through 2013. They’ve expressed interest in re-signing shortstop Rafael Furcal, acquired near the trade deadline and approaching free agency.

Mozeliak said Berkman’s contract left the Cardinals flexibility to get a deal done with Pujols.

"Getting into payroll and where we’re going to be, I know that’s a hot topic for you gentleman, but it’s not real relevant at the moment," Mozeliak said. "A lot of factors go into that and where we see that going will really depend on how things trend this offseason."

Berkman battled a left knee injury and batted a career-worst .248 with 14 homers and 58 RBIs for the Astros and Yankees last year. He briefly considered retiring before resuming training and finding a home in St. Louis, which gave him an $8 million deal for 2011.

"It’s a very good day. It’s a very good day for next year. We’re concentrating on today and this year," manager Tony La Russa said.

Berkman’s presence batting fifth has given the Cardinals depth behind Pujols and Matt Holliday. Berkman has been hitting cleanup since Holliday injured his right hand a week ago and was batting .394 this month.

He was also among the league leaders with a .412 on-base percentage and has been adequate in right field, his first full-time duty as an outfielder since 2004.

"I’m at a point in my career where I’m OK going one year at a time," Berkman said. "I don’t know how much longer I want to play or that I’ll be able to play at a high level.

"I want to earn my money and I feel like going year to year that’s the way to do it."

Berkman’s presence leaves promising Allen Craig without a position for now. Craig was batting .308 with eight homers and 33 RBIs in limited duty and has been filling in at left field for Holliday.

"He’s an up and coming talent that is going to get a lot of playing time regardless," Mozeliak said. "When you have that type of young player, you try to give him opportunities. But having someone like Lance and the opportunity to bring him back, it was just too compelling to pass up."