To seal the win, the GOP drew on backing from hard-right voters in rural, deep-red states, where Trump's nativist, racially tinged rhetoric and insult-laden discourse were as stirring for conservatives as they were infuriating to liberals elsewhere.
"Donald Trump went out and worked his tail off," Sen. Cory Gardner, R-Colo., who heads the Senate GOP's campaign committee, said in an interview. He cited Trump rallies that drew thousands in crucial states during the campaign's closing weeks and added, "The president was THE factor."
The significance of the Republican victory in the Senate, which the party has dominated for the past four years, was magnified because Democrats wrested House control from the GOP. That's a sure-fire formula for two years of legislative gridlock and positioning for the 2020 presidential and congressional elections.
Republicans retained Senate seats in the South, Midwest and West and ensured at least a 51-49 majority, equal to their current margin. With four races unresolved early Wednesday, Republicans stood a chance of expanding their majority with wins possible in Florida, Arizona, Nevada and Montana.
They paved their path to victory by defeating Democrats Joe Donnelly of Indiana, Heidi Heitkamp of North Dakota and Missouri's Claire McCaskill. They kept competitive seats in Texas, where Sen. Ted Cruz fended off Rep. Beto O'Rourke, the well-financed liberal darling, and Tennessee, where Rep. Marsha Blackburn prevailed.
Trump called Senate Majority Leader Mitch McConnell, R-Ky., "to congratulate him on the historic Senate gains," White House spokeswoman Sarah Sanders said. It was just the second midterm election in over three decades in which the party holding the White House gained seats.
The Republican Senate win was especially significant because that is where nominations are confirmed — including for Supreme Court justices and federal judges, a top GOP priority. The GOP agenda includes tax and spending cuts, trade, immigration restrictions and curbs on Obama's health care law. Short of compromises, perhaps on infrastructure, its initiatives would go nowhere in the House.
Even passing many bills will be difficult for the Senate. The GOP will fall well short of the 60 votes needed to break through Democratic filibusters, procedural delays that kill legislation. Though Republicans entered the night commanding the Senate only narrowly, a crucial piece of math worked in their favor: Democrats and their two independent allies defended 26 seats, Republicans just nine.
"Senate Democrats faced the most difficult political map in 60 years," Sen. Chris Van Hollen, D-Md., chairman of Senate Democrats' political arm, said in a statement. He lauded his party for winning at least half the 10 seats they were defending in states Trump carried in 2016 and for preventing Republicans from capturing a filibuster-proof majority.
Blackburn, a conservative and ardent Trump backer, defeated former Tennessee Gov. Phil Bredesen, 74. Bredesen had promised a bipartisan approach if elected and had won the endorsement of music star Taylor Swift.
Heitkamp lost to GOP Rep. Kevin Cramer, whom Trump persuaded to seek the Senate seat. Heitkamp was hurt late in her campaign by an ad that mistakenly named some women as victims of sexual abuse. McCaskill was denied a third term by Josh Hawley, 38, Missouri's hard-right attorney general, who called McCaskill too liberal for the state.
Democratic Sen. Joe Manchin was re-elected in West Virginia, which Trump captured by 42 percentage points in 2016. Democratic incumbents also prevailed in Ohio, Pennsylvania, Michigan and Wisconsin, which Trump carried narrowly two years ago.
Tuesday's midterms were among the most bitter in years, with Trump stoking conservatives' fears of caravans of immigrants traversing Mexico and inaccurately painting Democrats as broadly striving to bring socialism to the U.S. He himself said the contest would be a referendum on his presidency.
Democrats hoped their supporters would surge to the polls. Fueling their intensity were Trump's anti-immigration stances, his efforts to dismantle health care protections enacted under President Barack Obama and the #MeToo movement's fury over sexual harassment.
"Ever since President Trump has been in office, it has just been not the country that I am used to or that I thought I would be in," said Sarah Roth, 22, a Democratic voter from Minnetonka, Minnesota. "And so this really was my opportunity to help this country in changing who is making the decisions."
AP VoteCast, a national survey of the electorate conducted by The Associated Press, highlighted Trump's impact on voters. Nearly 4 in 10 said they were casting ballots to express opposition to him, while just 1 in 4 said their vote was an expression of support.
"I believe he values immigration, but he wants to make sure we're safe," said Tina Newby of Wetland, Michigan, a GOP voter. "I like the fact that he is not a politician, and I forgive some of the socially incorrect or politically incorrect things that he says."
Vermont independent Sen. Bernie Sanders and Democrats Elizabeth Warren of Massachusetts, Kirsten Gillibrand of New York and Minnesota's Amy Klobuchar were easily re-elected. All three and Sherrod Brown, a pro-labor senator victorious in Ohio, are considered potential 2020 Democratic presidential contenders.
Democrat Sen. Bob Menendez won a third Senate term in New Jersey, despite a federal bribery indictment that prosecutors dropped this year after a mistrial. Also victorious was Republican Mitt Romney, the vanquished 2012 GOP presidential candidate who grabbed an open Utah seat.
AP VoteCast is a nationwide survey of more than 120,000 voters and nonvoters conducted for the AP by NORC at the University of Chicago
AP reporters Jeff Baenen in Minnetonka, Minnesota, and John Flesher in Traverse City, Michigan, contributed.