The White House declared victory in the midterm elections Tuesday, citing Republican victories in contested Senate races, even as NBC News projected that Democrats would capture control of the House from the GOP for the first time in eight years.

"Tremendous success tonight," President Donald Trump tweeted, after it became clear Republicans would retain control over the Senate and possibly add to their majority there. "Thank you to all."

White House press secretary Sarah Sanders explained the interpretation of victory by saying the president had spent the last week campaigning heavily for Senate candidates.

"We are seeing that pay off," she said on NBC Tuesday night. "Certainly in places like Indiana, Tennessee, Texas, all places that the president came in [and] helped close the deal."

Trump held an extensive series of rallies across the country, mostly in states he won that featured competitive Senate races, starting right after Independence Day and ending Monday night with a three-stop tour through Ohio, Indiana and Missouri.

NBC projects that the Senate will remain in Republican hands. But as of late Tuesday night, it remained unclear just how many of several outstanding tight Senate races would tilt in the GOP's favor.

And Trump will now have to deal with a Democratic House for the next two years — a House that will have the power to block his legislative agenda, investigate his administration, subpoena his aides, and shape debates on the House floor to help position Democratic candidates for the 2020 presidential election.

"The president will fight for exactly what he lays out, regardless of who is in control in the House," Sanders said. "The president will be able to work with Democrats and Republicans to make sure we're getting things done. Because that's what he came to Washington to do."

Rep. Stephanie Murphy, D-Fla., a rising star among her party's more moderate faction, said that transportation and infrastructure policy could be an area where Trump and a Democratic House can work together to get an early shared win.

"Look for daylight where you can agree and there’s a vehicle to make a run for it," she said.

Despite the GOP's loss of the House — the exact numbers were still coming in late Tuesday — Trump felt validated by his decision to focus on strict immigration policy, rather than just the state of the economy, during the closing days of the campaign, according to sources inside and close to the White House who spoke to NBC on the condition of anonymity.

Many Republican establishment figures had hoped he would talk up the economy and abandon harsh rhetoric on immigration at the end of the campaign, fearing that his words — and proposals like sending thousands of troops to the U.S. border and ending "birthright citizenship" — would backfire on the GOP.

But Trump believed he was able to use immigration to change the topic from “the left’s closing argument, which was all health care,” according to one outside adviser.

Trump hosted a reception for some of his close friends, advisers and donors at the White House Tuesday night, and sources said the president was in a good mood as he received updates on the political battles playing out across the country. His allies were quick to point out places where candidates he'd campaigned for had won.