Those numbers from Philadelphia did not look good at all, and a ripple of alarm went through the war room late Tuesday. More Democrats than forecast had turned out to vote in the city, so aides to Republican U.S. Senate candidate Pat Toomey reworked their spreadsheets, looking for the path to victory.

At 10 p.m., Democrat Joe Sestak was holding a sizable lead in the closely watched contest - until, bit by bit, Republican areas reported in with better margins than the Toomey team could have hoped.

In the end, the Republican had an unassailable lead of 77,437 votes out of 3.9 million cast, or 51 percent to 49 percent, with 99 percent of the state's precincts counted Wednesday.

Of course, Toomey benefited from the wave against the policies of President Obama and the Democratic Congress. A conservative former congressman from the Lehigh Valley, Toomey campaigned hard against deficit spending and the burgeoning federal debt, and called for extending the 2003 tax cuts to spur the economy.

Those who said they were "very worried" about the economy - a little more than half the Pennsylvania electorate Tuesday - gave 69 percent of their votes to Toomey, according to media exit polls.

A look at those polls, along with patterns in state returns and interviews with analysts and officials in both campaigns, showed that Toomey also won because a lot of seemingly small things went right for him.

"We really had historic Republican turnout numbers in the rest of the state," Toomey campaign manager Mark D. Harris said Wednesday.

Toomey split Philadelphia's four suburban counties with Sestak, a second-term congressman from Delaware County, a better performance than recent statewide GOP candidates managed. He won higher vote margins in Republican strongholds than usual for a midterm election, and he carried several Western Pennsylvania counties, including Beaver, Washington, and Fayette, dominated by conservative Democrats.

For instance, Toomey reaped a 54,000-vote margin in Lancaster County, after planning for a robust but more normal 40,000. The Republican also outperformed projections in Lycoming and Mifflin Counties..

Toomey carried Chester County by 8 percentage points and Bucks by 7 percentage points, while Sestak carried Delaware 56 percent to 44 percent and Montgomery 54 percent to 46 percent.

Toomey carried independents by 55 percent to 44 percent. They had been crucial to Democratic victories in 2006 and 2008.

More than a third of the voters said they were motivated by opposition to Obama, and they went overwhelmingly for Toomey.

Republicans focused turnout efforts on GOP voters who regularly cast ballots in presidential years but often skip midterms, targeting them for calls, literature, and door-to-door visits, through a combination of the party's Victory program, the various congressional campaigns, and Toomey's own campaign.

Toomey also had backing from members of the tea party, who volunteered for his campaign and those of several Republican congressional candidates.

In addition, Pennsylvania's seven competitive U.S. House races likely helped Toomey by boosting Republican turnout, as did the strong performance of the party's gubernatorial candidate, Tom Corbett, according to Villanova University political scientist Lara Brown.

Democrats also fought to fire up their core voters, who were less motivated than Republicans to cast ballots this year, polls indicated.

On Sestak's side were Organizing for America, the Vote 2010 coordinated campaign and other groups designed to help the entire Democratic ticket, local parties, and his own army of volunteers.

In the end, they generated turnout a shade under 40 percent in Philadelphia - solid for a midterm, but not enough in a wave election.

"There's no one thing to point to," a Sestak adviser said, adding that the campaign was simply "overwhelmed by the national wave."

Sestak partisans also attached blame to a surge in spending by third-party interest groups, freed up by a recent Supreme Court decision allowing direct corporate funding in campaigns. The campaign estimated it was outspent by about $6 million on television because of the groups' ads boosting Toomey.

"The money that poured in from third-party operations bears looking at," said Bill Walsh, director of Sestak's congressional district office. "Is this what we want in our democratic process? The country needs to ask that."

Late Wednesday afternoon, Sestak bounded up the short flight of stairs between rooms of his campaign headquarters on Baltimore Pike in Media. He was wearing his usual short green military bomber jacket and jeans.

All around, staffers were busy packing up. Boxes were everywhere. Folding chairs were stacked in the corners, unused manila envelopes were piled on a desk, computers and cords were gathered together, three large poster boards covered with old 3x5 party photos were leaning against a wall near the front door.

The sound packing tape makes as it is ripped off a roll could be heard in the background.

"I normally don't duck interviews," Sestak said, shaking hands as he declined to talk about the loss. "Let me have my press [staff] talk to you."

He called for an aide to join him and disappeared into a room closing the door behind him. A small paper sign, "Office of the Future Senator Joseph Sestak," was taped on the front.

Toomey, for his part, was spending time with his family in Allentown, though he did a couple of television interviews and chats with talk-radio hosts who had long been supportive of him.