Sen. Pat Toomey (R., Pa.) won a second term early Wednesday, defeating Democrat Katie McGinty as Republicans surged to a series of victories that stunned pollsters, analysts and the mainstream media.

With nearly 98 percent of the vote counted, he led McGinty by fewer than two percentage points, but appeared to have enough of a lead to win.

"I am really deeply humbled by this victory," Toomey told supporters gathered in Lehigh County around 1:45 a.m. "Let's face it, this was a tough campaign."

His narrow victory followed a string of Republican wins in what were expected to be tough battleground contests -- and slammed the door on Democrats' hopes of taking control of the Senate.

Speaking to disappointed supporters in Philadelphia, McGinty congratulated Toomey on his victory.

It came on a night when Republican presidential nominee Donald Trump was closing in on a monumental upset over Democrat Hillary Clinton in the presidential race. Trump's upset victory in Pennsylvania, the first by a GOP presidential nominee in decades, all but assured him the presidency.

Democrats had made Toomey one of the top targets in the country, but they saw their efforts in Keystone State fall short while also losing key races in North Carolina, Wisconsin, Florida and Ohio.

Toomey, narrowly swept into office as a true conservative in 2010, won another tight contest after campaigning this year as an "independent voice" willing to cross the aisle and stand up to presidents in either party.

Seeming to also discount the idea that Trump might win the White House, he had promised to be a check on a potential Hillary Clinton presidency.

In winning the most expensive Senate race in history, Toomey was helped by massive turnout in rural areas -- the state seemed on the verge of backign a Republican for president for the first time since 1988.

The ending Tuesday arrived after a brutal campaign that set records for spending — more than $155 million had poured in.

At Toomey's election night party in Breinigsville, near Allentown, about 150 people milled about in the ballroom of a Holiday Inn. Supporters said Toomey is a senator who cares about the people and is accessible to them — and noted the importance of keeping Republican control of the Senate.

"He gets things done," said Linda Larson, 56, of Carlisle. "I know he cares about our jobs and that businesses are doing well."

Larson said she was pulling for all Republicans running, not just Toomey and Trump. She said she'd be sick if Clinton won.

Linda Fazio of Conshohocken made an hour-long drive to be at Toomey's Election Night party.

"I want to support him either way," she said.

The mood at Democrats' Election Night party in Philadelphia slowly shifted from confidence to palpable nervousness as results trickled in and Trump outpaced projections.

Gov. Wolf — after at first saying he felt good about McGinty's chances — told attendees it would be a long night. By the end, few celebrants remained at what Democrats hoped would be their victory party.

Democrats had thought that Trump's presence would help them in a state that has tilted blue in previous presidential election years.

But he was running stronger in Pennsylvania than many expected, perhaps even Toomey. He captured the state around 1:40 a.m.

The senator did not take a firm stand on the GOP nominee during the campaign -- not until he voted around 6:45 p.m. Tuesday. He told reporters that he had "serious questions" about the nominee's temperament and judgment but that "we've just gotta change the course we're on."

McGinty had hammered Toomey as "spineless" for refusing to take a stand sooner, with those attacks making up the bulk of her message in the race's final weeks.

The Pennsylvania contest had become a proxy battle by the two national parties.

McGinty was bidding to become Pennsylvania's first woman senator.

Long a high-level aide in Washington and Harrisburg the former chief of staff for Wolf was picked by Democratic leaders in Washington to be the face of a crucial campaign and heavily-backed by Democratic leaders, including Clinton, President Obama and Vice President Biden.

A relative unknown, McGinty had pledged to support Clinton and middle class Americans she argued were left behind by a changing economy, and Republicans such as Toomey.

Toomey had painted her as a "rubber stamp" for Democratic leaders, and pitched himself as a check on a potential Clinton White House.

He won an often ugly race colored by deeply personal attacks.

Toomey, once a darling of the right, had to walk a political tightrope in recent years -- needing to please both his conservative base while trying to appeal to moderate swing voters.

His efforts appeared to pay off Tuesday.

@JonathanTamari