Sen. Ted Cruz, R-Texas, was projected to narrowly win a second term Tuesday by defeating Democratic challenger Beto O’Rourke, who became a national media sensation during the campaign and benefited from an outpouring of outside donations and spending.

With 88 percent of precincts reporting, Cruz led O'Rourke by 51 percent to 48 percent and a margin of approximately 235,000 votes out of more than 7.6 million ballots cast.

FULL MIDTERM RESULTS

"God bless Texas!" a jubilant Cruz told supporters at his victory party in Houston.

"Ted Cruz knows how to get the job done for Texans and tonight’s victory shows voters trust him to put their values first,” National Republican Senatorial Committee Chairman Cory Gardner said in a statement. “Senator Cruz has been an unfailing champion for secure borders, a prosperous economy and the American rule of law, and we congratulate him on his reelection.”

Democratic hopes for an improbable upset had been raised by unusually high early voting numbers. Nearly 4.9 million people voted in Texas' 30 largest counties during the early-voting period, surpassing the total number of votes cast throughout the state in the last midterm election, according to the secretary of state’s office.

MIDTERM LIVE BLOG

However, the polls gave Cruz a consistent lead in the race. On Election Day, the Real Clear Politics poll average showed the incumbent with a 6.5 percentage point advantage, more than double the 3.2 percentage point lead the Republican had in mid-September.

O’Rourke, a three-term congressman and former El Paso city council member, was attempting to become the first Democrat to win statewide office in Texas since 1994 -- the longest such losing streak in the country. His challenge to Cruz was bolstered by more than $70 million in donations from across the country, making the race the most expensive Senate contest in U.S. history.

"All the money in the world was no match for the people of Texas," Cruz said.

O’Rourke’s unconventional background (he spent time in a punk rock band) and uncommon work ethic – he famously visited all of the Lone Star State’s 254 counties -- made him the subject of attention from all corners of the mainstream media. He was profiled in publications as varied as The New York Times, Vanity Fair, Rolling Stone and GQ (twice) and speculation that O’Rourke could use a win or close loss as a springboard to a spot on the Democrats’ 2020 ticket began to percolate.

Cruz praised O'Rourke in his victory remarks Tuesday evening, acknowledging that "millions across this state were inspired by his campaign." Hours later, O'Rourke worked blue at a baseball stadium in his hometown of El Paso, telling supporters he was "so f---ing proud of you guys."

"Tonight's loss does not diminish how I feel about Texas or this country," O'Rourke added.

But the Democrat also received some unwanted attention. In August, the Houston Chronicle reported details of a 1998 police report detailing O’Rourke’s arrest for drunk driving. According to witnesses, O’Rourke, then in his mid-20s, “lost control of his car and hit a truck, sending his car careening across the center median into oncoming lanes.” Other eyewitnesses claimed that O’Rourke tried to drive away from the scene and two breathalyzer tests showed that he had a blood-alcohol level of 0.136 and 0.134. The charge was later dismissed.

Cruz, for his part, sought to paint O’Rourke as a member of the “hard left” who had been worked into a frenzy by opposition to President Trump, who led a rally for Cruz in Houston last month. The Republican cited O’Rourke’s support for Bernie Sanders’ “Medicare for all” plan, his calls to impeach President Trump and his openness to abolishing the Immigration and Customs Enforcement agency.

O’Rourke also handed Cruz a campaign issue in late August, just as polls showed the race beginning to tighten. In response to a question about NFL players kneeling during the playing of the national anthem, the Democrat said: “I can think of nothing more American than to peacefully stand up, or take a knee for your rights anytime, anywhere, any place.”

The comments earned O’Rourke national attention and won the approval of basketball star LeBron James, but proved to be red meat for Cruz who responded by invoking soldiers, sailors, airmen and Marines saluting the flag.

“When Beto O’Rourke says he can’t think of anything more American, well I got to admit, I can,” the Republican said. The Cruz campaign cut a commercial responding to O’Rourke that featured a double-amputee Vietnam veteran named Tim Lee.

“I gave two legs for this country,” Lee said in the spot. “I’m unable to stand, but I sure expect you to stand for me when that national anthem is being played.”

Cruz insisted in the race’s final days that he had the backing of a "commonsense supermajority" of conservatives – including registered Democrats -- that O’Rourke could not overcome.

But according to the Fox News Voter Analysis, a whopping 97 percent of Democrats voted for O'Rourke, with just 2 percent crossing party lines to vote for Cruz. By contrast, 8 percent of Republicans voted for O'Rourke. The race also cast Texas' city-country divide into sharp relief. Sixty percent of urban residents backed O'Rourke, with just 38 percent going for Cruz. In rural areas, 59 percent of the voters broke for Cruz while 38 percent voted for O'Rourke.

"I am so proud each and every day to stand up and fight for you and defend you," Cruz said. " ... and it is my hope, with the bitterness and division we see nationally, we can come together, respecting each other's decency, humanity and treating each other how we should treat each other."

The Associated Press contributed to this report.