Montana Democratic Sen. Jon Tester is the apparent winner in his bid for a third term, fending off a strong challenge from Republican Matt Rosendale, NBC News reported.

NBC News made the call Wednesday afternoon. The race had been too close to call on election night. Tester survived despite voting no on Brett Kavanaugh's confirmation to the Supreme Court. Decisions to vote against the judge doomed some of his red-state Democratic colleagues.

Tester's apparent victory over Rosendale, Montana's state auditor, came despite the surprise move last week by long-shot Libertarian Party nominee Rick Breckenridge to throw his support to the GOP candidate.

The 62-year-old Tester's apparent win would be seen as a rebuke to President Donald Trump. Trump, in his 2016 presidential campaign, had won 50 out of Montana's 56 counties.

The president also singled out Tester, a Senate Veterans Affairs Committee member, for harsh criticism after the senator helped scuttle the nomination of Trump's personal physician, Dr. Ronny Jackson, as secretary of the Department of Veterans Affairs.

But Democrats in Montana painted Rosendale as a carpetbagger, calling him "Maryland Matt."

Rosendale, a Baltimore native and real estate developer, moved to Montana only 16 years ago, while Tester is a third-generation resident of the state.

Tester's apparent victory was announced as Trump was giving a White House news conference. When told of the development, Trump congratulated him, but then said sarcastically, "I'm sure you're very happy."