But she differs with McCain on a controversial environmental issue that centers on her home state: she has been pushing for a new pipeline that would pump trillions of cubic feet of natural gas from the North Slope to the lower 48 states in the hope of delivering Alaska another economic boom. McCain's opposition to drilling — even after he changed positions and began advocating for off-shore oil drilling — has upset many Republicans.

For its part, the Obama campaign was dismissive of the selection.

" Today, John McCain put the former mayor of a town of 9,000 with zero foreign policy experience a heartbeat away from the presidency," Bill Burton, a spokesman for the Obama campaign, said in a statement. "Governor Palin shares John McCain's commitment to overturning Roe v. Wade, the agenda of Big Oil and continuing George Bush's failed economic policies — that's not the change we need, it's just more of the same."

The choice of Palin was a closely guarded secret, and she flew under the political radar for months as McCain searched for a running mate. Much of the public discussion in recent days had focused on Mitt Romney, the former Massachusetts governor and McCain's one-time rival for the Republican nomination; Governor Tim Pawlenty of Minnesota; Tom Ridge, the former governor of Pennsylvania and Homeland Security secretary, and Senator Joseph Lieberman of Connecticut, the Democrat-turned-independent who was former Vice President Al Gore's running mate in 2000. Social conservatives were relieved and highly pleased.

"They're beyond ecstatic," said Ralph Reed, the former head of the Christian Coalition. "This is a home run. She is a reformer governor who is solidly pro-life and a person of deep Christian faith. And she is really one of the bright shining new stars in the Republican firmament."

Palin is known to conservatives for choosing not to have an abortion after learning two years ago that she was carrying a child with Down syndrome. "It is almost impossible to exaggerate how important that is to the conservative faith community," Reed said.

Whether her selection will improve McCain's appeal to women who had supported Clinton is unclear. Both McCain and Palin oppose abortion rights, an important issue for some women. And a major theme of the Democratic convention that just concluded in Denver was both Hillary Rodham Clinton and former President Bill Clinton urging supporters to unite behind Obama.

The choice of Palin was reminiscent of George W. Bush's selection of Dan Quayle, a young United States senator, as his running mate in 1988. The media and most in the Republican Party were caught unaware by the announcement of a figure relatively unknown outside Indiana.