Editor's note: This story has been updated to reflect the final election results.

U.S. Sen. Ted Cruz, R-Texas, narrowly defeated Democratic challenger Beto O'Rourke Tuesday evening in what appeared likely to be one of the closest U.S Senate races in Texas in decades.

With all precincts reporting, Cruz won by about 219,000 votes, or 2.6 percentage points, over O'Rourke. While Cruz had a strong showing across most of rural Texas, O'Rourke narrowed the margin by winning urban counties and coming within striking distance in some Texas suburbs.

Loading...

Delivering his victory speech, Cruz cast the race in dramatic terms, saying it was not about either candidate but a "battle of ideas" and a "contest for who we are and what we believe in."

"This was an election about hope and about the future of Texas," Cruz said, "and the people of Texas rendered a verdict that we want a future with more jobs and more security and more freedom."

Cruz thanked O'Rourke, saying he "poured his heart" into the campaign and "worked tirelessly," making sacrifices as a father. Acknowledging that "millions across this state were inspired by his campaign," Cruz appealed to O'Rourke's supporters, saying he wanted to represent them too.

But Cruz did not hold back about the challenge he said he faced.

"We saw an assault that was unprecedented," Cruz said. "We saw a $100 million race with Hollywood coming in against the state, with the national media coming in against the state. But all the money in the world was no match for the good people of Texas and their hard work."

O'Rourke took the stage later in in the evening to address a crowd of several thousand supporters at a baseball stadium in El Paso.

"I just now had the opportunity to talk to Senator Cruz ... to congratulate him on his victory, and wish him well going forward," O'Rourke said. "I am as inspired, I'm as hopeful as I have ever been in my life, and tonight's loss does nothing to diminish how I feel about Texas and this country."

"I'm so fucking proud of you guys," O'Rourke declared, during a speech that was being broadcast on national cable networks.

O'Rourke, who some have speculated could be a potential presidential contender, was vague about his future plans, though he has dismissed that theory. He concluded his speech – and his campaign – with a simple farewell: "We will see you out there, down the road."

"They made it close"

The two candidates' Tuesday night speeches followed a three-hour rollercoaster for those watching results trickle in, as Cruz and O'Rourke repeatedly traded narrow leads.

At about 9:25 p.m., Cruz's supporters at his election night party in a Houston hotel broke out in cheers and a chant of "Cruuuz!" as Fox News called the race for him. "We want Ted!" supporters shouted as they moved closer to the stage, hoping to hear from the victor.

It was a dramatic shift from shortly before 9 p.m., when Cruz's chief strategist, Jeff Roe, took the stage to address concerned supporters looking at returns that showed O'Rourke in reach of a historic upset. Roe told them "everything's good" and said the campaign expected Cruz's lead to grow once the results in more rural counties came in.

"Anybody that’s really clenched — you can release a little bit — it’s OK," Roe said, suggesting he nonetheless expected to be "in for a little bit of a night."

The mood at the O'Rourke election night party in El Paso was upbeat well into the evening. But the mood quickly soured once it became clear that most news outlets had called the race in favor of Cruz.

"I'm very surprised. I'm very disappointed," said 80-year-old Olivia Lara, an O'Rourke supporter who said she votes in every election. "He worked so hard. It's very sad for El Paso."

Cruz supporters acknowledged being spooked as the first early vote results came in, giving O'Rourke a lead.

"At first I was a little worried, but we knew that after the big cities were done, that the rural counties would pull us in," said Mike Diaz, a 39-year-old engineer from Cypress.

As for the closer-than-usual margin of victory for a statewide Texas Republican, Diaz and other Cruz backers chalked it up to financial firepower that O'Rourke brought to the race.

"It was a good, hard-fought battle, but they dumped so much money and so much advertising — they made it close," Diaz said.

The race between Cruz and O'Rourke emerged in recent months as one of the hottest in the country during this midterm election season, as O'Rourke, a relatively unknown congressman just two years ago, cobbled together the most competitive statewide campaign by a Texas Democrat in over a decade. As Election Day drew closer and polls suggested a tightening race, Democratic hopes abounded that O’Rourke was cracking the code: energizing long-beleaguered Texas Democrats, expanding the electorate and putting himself in position to be the first of them to win statewide office in over two decades.

After making little secret of his intentions for months, O’Rourke entered the race on the last day of March 2017, announcing his campaign alongside his wife in El Paso. He laid down some early markers, promising to run a positive campaign, not accept PAC money and eschew pollsters and consultants.

For a period, the prospect of a competitive primary loomed as U.S. Rep. Joaquin Castro of San Antonio considered a run as well. But about a month after O’Rourke launched his bid, Castro passed on a run, giving O’Rourke a relatively clear shot at the nomination.

O’Rourke immediately got to work on an ambitious goal: visiting all 254 counties of Texas. That push defined much of the first half of his campaign as he racked up thousands of miles holding town halls throughout the state, building the case that he would be the senator who would show up for all of Texas.

Heading into the March 6 primary, there was little concern O’Rourke would dominate in his first statewide test. But he received an underwhelming 62 percent of the vote, with most of the rest going to two unknown candidates. He also lost a number of heavily Hispanic counties in South Texas, auguring concerns about his ability to turn out the demographic long believed to be key to a Democratic revival in the state.

The night of the primary was notable for another reason: Cruz abruptly went on the offensive against O’Rourke after months of largely ignoring him. In a conference call shortly before polls closed, Cruz unloaded on O’Rourke as too liberal for Texas, and in an ad released later that night, mocked him for using the nickname “Beto” when his legal name is Robert Francis. ("Beto" is a Spanish nickname that the congressman has gone by since his youth.)

"Tough as Texas"

The following month, Cruz formally launched his re-election bid with a focus on extolling Lone Star State exceptionalism — especially in the wake of Hurricane Harvey. It was an ostensibly unifying message that complemented Cruz’s new campaign slogan — “Tough as Texas” — and punctuated a period of home-state re-engagement following his unsuccessful 2016 presidential campaign.

O’Rourke pressed forward with his 254-county tour. He completed it on June 9 in Gainesville, the seat of Cooke County, and did not let up afterward, continuing to keep an aggressive travel schedule that attracted growing national spotlight. It only grew brighter by mid-August, when O’Rourke’s remarks at a town hall defending NFL players who kneel during the National Anthem went viral.

By late summer, the mood of the race started to change. Things were tightening, according to surveys, and national Republicans began to develop some concern that it was getting too close for comfort.

The alarm was not helped by O’Rourke’s massive fundraising, which poured in online. He was out-raising Cruz period after period, and he posted an astonishing $38 million in the third quarter of 2018 — a new record for the biggest fundraising quarter ever in a U.S. Senate race.

The GOP calvary began to mobilize. The Club for Growth, a conservative group that was critical to Cruz’s 2012 election, announced it would spend seven figures to help fend off O’Rourke, and a parade of high-profile surrogates began to form.

None, of course, was more high-profile than President Donald Trump, who Cruz bitterly battled in the fight for the 2016 Republican presidential nomination. At the end of August, the president took to Twitter to announce he would headline a rally for Cruz in October — and he wanted to do it in the “biggest stadium” he could find in Texas. The two ended up reuniting on the first day of early voting — Oct. 22 — at the Toyota Center in Houston, where the president made clear they had buried the hatchet from 2016 and happily attacked O’Rourke as a “stone-cold phony.”

The fall also saw two debates between Cruz and O’Rourke, the product of grueling, months-long negotiations between the two sides. Meeting first in Dallas, O’Rourke displayed a more aggressive approach to Cruz, but it still left some supporters unsatisfied, especially as O’Rourke was getting buried by attack ads on TV while running exclusively positive spots. So in the second debate, held in San Antonio, O’Rourke swung harder at Cruz — to the point of adopting Trump’s old nickname for the senator: “Lyin’ Ted.”

Strategically, it was a pivotal moment for O’Rourke, and it was followed the next morning by the launch of three TV ads criticizing Cruz, a test of O’Rourke’s longtime vow to take the high road. Around the time, Cruz was riding high off the GOP enthusiasm generated by anger over Brett Kavanuagh’s confirmation to the U.S. Supreme Court, and he gleefully portrayed O’Rourke’s new tack as the hallmark of a flailing candidate.

But Cruz’s high was not forever. Polls suggested his lead began to narrow again during early voting, which itself was a key moment. Turnout was comparable to that of a presidential election year, with nearly 5 million Texans voting early in the 30 Texas counties where most registered voters in the state live.

At O'Rourke's election night party, some were already searching for a silver lining, predicting O'Rourke's bid will pave the way for a future Democrat to win statewide.

"Even if he doesn't get over the finish line, he's laid a foundation we can build upon," said Julián Castro, the former U.S. housing secretary and San Antonio mayor, and a possible presidential contender.

At one point later in the evening, a cover band played "Don't Stop Believin'."

Julian Aguilar contributed to this report.