Updated

President Trump wasn’t on the ballot this year, but it was clear that many Americans had the president on their minds as they voted in midterm elections.

Nearly 40 percent of voters said opposition to Trump was a reason for casting their ballots, according to AP VoteCast, a national survey of the electorate. Around 25 percent said they did so in support for the president.

The nationwide survey was compiled from answers given by more than 113,000 voters and 20,000 nonvoters.

Attitudes toward Trump influenced more than 6 out of 10 voters, the survey said.

The will of Democrats opposed to Trump drove the party’s base while Trump encouraged Republicans to vote by trying to cast the election as a referendum on his presidency.

FULL MIDTERM RESULTS

As Election Day neared, Trump put thousands of miles on Air Force One, hopping from one rally to another in a bid to energize Republicans by castigating Democrats and playing up hot-button issues such as immigration and crime.

“I’m not on the ballot, but in a certain way, I’m on the ballot,” Trump said in October. “I want you to vote. ... Pretend I’m on the ballot.” 

“I’m not on the ballot, but in a certain way, I’m on the ballot. I want you to vote. ... Pretend I’m on the ballot.”   

— President Trump, speaking to prospective voters in October

By Tuesday night, the Democratic Party had regained control of the U.S. House of Representatives while the GOP was projected to retain the Senate. Democrats needed to gain at least 23 seats in the House to win a majority.

The retaking of the House gives hopes to liberals looking to continue Special Counsel Robert Mueller's Russia investigation and possibly halt Trump's legislative agenda.

Nevertheless, Trump hailed the election a success in a tweet late Tuesday.

"Tremendous success tonight," the president wrote. "Thank you to all!"

According to VoteCast, around 6 in 10 women surveyed said they voted in favor of their congressional Democratic candidate while men were more split in their vote.

BETO BLOCKER: CRUZ TRUMPS O'ROURKE, WHO BROUGH IN RECORD-HIGH CAMPAIGN DONATIONS

Men living in urban areas favored Democrats 2 to 1 and small-town and rural voters went for Republicans by a smaller margin.

Non-white voters cast ballots 3 to 1 in favor of Democrats. In suburban areas, voters slightly favored Democrats by a 10-point margin.

Opposition to Trump was a motivating factor for Democrats but Republicans overwhelmingly supported the president.

Hot-button issues like immigration and health care were described as the most important issues by 25 percent of voters. Of those who listed health care as their top issue, 3 out of 4 voted for a Democrat with the same for Republicans who listed immigration as the most important issue.

About one-third of voters said Trump was not a factor in their votes.

The survey indicated most voters disapproved of Trump’s job performance. Trump scored positively on the economy and "for standing up for what he believes in” but negative marks for trustworthiness and temperament.

The politically motivated attempted bombings of Democratic figures and a mass shooting at a Pittsburgh synagogue prompted 2 in 10 Democratic and Republican voters to believe their own party's way of talking about politics has led to an increase in violence.

The Associated Press contributed to this report.