This post has been updated with new quotes throughout.

Pat Toomey pulled it off. Again.

After eking out a victory in 2010, the Republican won a second term in the U.S. Senate Tuesday by an even narrower margin -- less than 2 percentage points on a stunning Tuesday night. He defeated Democrat Katie McGinty.

While his victory coincided with Republican presidential nominee Donald Trump shocking the political world and winning Pennsylvania and the presidency, Toomey followed a very different path to his win.

The senator's strength showed in moderate suburban areas, where he outperformed Trump in wealthy, educated area where many voters were wary of the GOP nominee. He lagged Trump, meanwhile, in some more rural county where the president-elect ran most strongly.

Here is how the race broke down:

-- Toomey excels in Philly suburbs: 
Immediately after his 2010 victory, Toomey and his advisors knew he needed to craft a more moderate platform for this year, and he carefully picked his spots, most notably sponsoring a bill to expand background checks for gun purchases.

While declining until the last minute to back Trump, Toomey ran ads featuring two of Democratic Party's biggest names: President Obama praising that effort, and highlighted plaudits from former Gov. Ed Rendell.

It seems to have worked: Toomey trailed McGinty by just 56,000 votes in the moderate Philadelphia suburbs, while Trump lost the four collar counties by nearly 180,000, according to preliminary results. Toomey got nearly 48 percent of the vote in Bucks, Chester, Delaware and Montgomery counties, compared to about 43 percent for Trump.

He ran ahead of Trump in Philadelphia's populous suburbs, faring well in moderate areas the presidential candidate did not. Trump surged in rural and blue-collar outposts, where Toomey's Wall Street background didn't play nearly as well.

"We did it the way Republicans had done it for the past 20 years" when winning in Pennsylvania, said Mark Harris, a strategist who worked on Toomey's campaign. "Trump found a new way."

He even won two wards in Philadelphia, an aide said, and won a higher percentage in the city, 17, than the 14 his advisors had hoped for. In Lancaster and Cumberland counties, not too far removed from big cities, Toomey also outpaced Trump.

David Landau, chairman of the Delaware County Democratic Party, said the results suggest moderate, highly educated suburban Republicans were unwilling to support Trump but did back Toomey.

"Toomey was never going to able to appeal to some of the more blue-collar Democrats like Trump was," said John Brabender, a GOP consultant who worked with national Republicans on the race. "He did have more of a relationship with some of the more moderate [Republicans], particularly women, in the Southeast."

Trump scored much bigger wins in more rural areas like Westmoreland, Cambria and Washington counties, all in the state's southwest. Toomey won those places, but lagged the GOP nominee, perhaps because of his refusal to endorse Trump, his Wall Street past and his support for international trade.

But Trump -- far from proving to be the  anchor many predicted -- instead brought out a new wave of Republican voters, and Toomey was in position to benefit from a surge on the right, even if his margins fell short of Trump's.

Trump "had a unique relationship with conservative Democrats who did not like Clinton," Brabender said. "In many states, we saw that did not necessarily trickle down all the way down the ballot, [but] it did to some degree."

In Cambria County, for example, Trump won 67 percent of the vote, 9 points more than Romney in 2012. Toomey didn't do quite as well, but still came out of the county with a 14,000-vote margin.

Many Democrats believed Clinton needed to win the state by at least 4 percentage points to carry McGinty to victory.

"Once Hillary Clinton didn't win Pennsylvania, I think it was very difficult for Katie," Landau said, noting that margins in the presidential and Senate races were almost identical, showing that the two were linked.

-- Did Democrats pick the wrong candidate?
It didn't take long for the second-guessing to begin.

National Democrats placed a huge bet on McGinty, who had never held elected office, had one unsuccessful campaign to her name and campaigned on a generic Democratic message. But party leaders thought she was a better option than the free-wheeling Joe Sestak and spent heavily to ensure her victory in April's Democratic primary.

This morning two longtime Pennsylvania operatives -- one Democrats and one Republican, both asking for anonymity to speak frankly -- questioned if that was the right move. They pointed out that while McGinty ran as the insider's pick, Sestak had the outsider streak that voters were clearly looking for this year.

He wasn't polished -- which irked national Democrats but may have been an asset in 2016. He also could have countered Toomey's national security message with his record as a three-star admiral.

And while McGinty latched onto Hillary Clinton, Republicans said that gave them an opening to cast her as a "rubber stamp" for an unpopular Democratic nominee.

"That was a big deal, and they made no effort to fight that argument," Harris said. "If there's one strategic decision that played out for us, I think it was that one."

Brabender, who scripted GOP attack ads, said it helped them paint McGinty as a politico profiting from her government ties.

"People saw her in some ways the same way they did Hillary Clinton, and that is someone gaming the system," he said.

Of course, it's easy to question McGinty in hindsight. She improved as a candidate as the race went on, and Sestak had his own liabilities, including a Congressional voting record Toomey could mine for attacks and one loss to the incumbent already.

A spokeswoman for Democrats' national Senate campaign arm said the organization is "incredibly proud" of McGinty's campaign and noted that her race was one of the tighest battleground Senate contests in the country.

It's impossible to say if any candidate would have made a big difference in a year when Democrats suffered crushing losses across the board. At the very least, the wounds from the primary have re-opened.

-- The men and women in blue back Toomey:
Toomey spent lots of time promoting his work with and endorsements from police unions. His camp believes that helped him stay close in Philadelphia. The two wards he won were both in Northeast Philly, where one ally surmised that he benefitted from the presence of police who live in that working class neighborhood. (Ironically, the same area where McGinty grew up, in a family headed by a Philadelphiapoliceman).

On Election Day, Philadelphia Fraternal Order of Police president John McNesby sent out a robo-call warning voters about a late-campaign donation McGinty received from Debo Adegbile -- a one-time Obama administration civil rights nominee who Toomey and police fiercely opposed because of his leadership of to an NAACP legal team that aided convicted cop-killer Mumia Abu-Jamal in his death penalty appeal.

-- Casey's reelection looks murky:
Pennsylvania may have another rough Senate race on the horizon: Democrat Bob Casey is on the ballot in 2018. Last night's results have already shifted the dynamic in that contest.

Trump's victory, turning Pennsylvania red in a presidential year for the first time since 1988, exposed a  vein of potential Republican voters who canceled out Democrats' usual strength in Philadelphia and the suburbs. If another Republican can retain support from those working-class voters, he or she could enjoy a bump against Casey in a year when there will not be a presidential candidate on the ballot to motivate Democrats in Philadelphia.

On the other hand, Casey is now assured of running as part of the opposition in a mid-term election. Typically, the party out of the White House wins big as a backlash to the president in the first mid-term race. Casey surely did not expect to be in that position last night. But it may give help him.

-- Women are shut out: 
McGinty's loss continues Pennsylvania's history of never sending a woman to the U.S. Senate. It also means the state's 20-person Congressional delegation will remain all male.

This post has been corrected. The original included incorrect data on Toomey's vote totals in the Philadelphia suburbs.

You can follow Tamari on Twitter or email him at jtamari@phillynews.com.