Incumbent Republican Sen. Pat Toomey of Pennsylvania narrowly defeated Democratic contender Katie McGinty in the early morning hours Wednesday, CNN reported. He won by just under 100,000 votes with an estimated 97 percent of precincts reporting as of 3 a.m.

The race may have been the undercard in the battle to win Pennsylvania between presidential contenders Hillary Clinton and Donald Trump, but it was also the most expensive and deeply fought Senate races in history, with more than $162 million going to get-out-the-vote efforts and ceaseless television advertising.

At stake was not only who will represent the Keystone State in the Senate, but control of the Senate itself, with a number of Republican incumbents, like Toomey, in very tough races. In the end, the Republicans took the Senate 51-47.

For her part McGinty, who was once head of the state’s environmental protection agency and has never held public office, tried to tie Trump and his controversial bid for the White House like an anchor around Toomey’s neck.

Toomey, who won his Senate seat in 2010, shot back with ads throwing shade at McGinty for awarding environmental agency grants to organizations her husband had served as a consultant.  

But as an indication at how carefully Toomey tried to distance himself from Trump while not alienating the businessman’s passionate Republican supporters, Toomey didn’t announce that he had chosen to vote for Trump until just an hour before polls closed.

Nikki M. Mascali contributed to this report.