Sen. Ted Cruz survived the most competitive U.S. Senate race in 40 years in Texas thanks to three key parts of the state.

Cruz targeted the Texas Panhandle, a half-dozen counties in East Texas and the Houston suburbs as he closed his campaign. He held rallies in each of those areas, pleading with conservative supporters to vote in big enough numbers to counter the record turnout in Texas cities that powered Democrat Beto O’Rourke.

And those conservative voters delivered, providing Cruz with almost 250,000 more votes than O’Rourke — slightly more than Cruz’s margin of victory statewide.

As of late Wednesday, the Texas Secretary of State had Cruz winning the U.S. Senate race over O’Rourke 50.9 percent to 48.2 percent. It is the first time any U.S. Senate race has been decided by less than 10 percentage points since 1978.

“Millions across the state were inspired by his campaign,” Cruz told supporters of O’Rourke at his victory celebration in Houston on Tuesday. “They did not prevail and I’m glad the people of Texas chose a different path.”

No region was more important to Cruz than the Harris County suburbs. In Montgomery, Waller and Chambers counties, Cruz built a nearly 100,000-vote margin of victory there, claiming almost 73 percent of the vote, and nearly half of his overall margin of victory.

That was critical for Cruz as O’Rourke pounded him in Harris County. O’Rourke won nearly 200,000 more votes than Cruz in Harris, even though that is Cruz’s home county and Cruz won it outright in 2012.

While O’Rourke won 19,000 more votes in Montgomery County than Democrat Paul Sadler got in his race against Cruz in 2012, his margin of defeat in Waller and Chambers was actually worse than Sadler’s by about 2,000 votes.

Cruz needed all of those votes to counter what he called an “assault that was unprecedented” from Democrats and O’Rourke.

O’Rourke cleaned up along I-35

The Interstate 35 corridor shows the unprecedented nature of O’Rourke’s campaign. In the 19 counties on I-35 from Laredo to the Oklahoma border, O’Rourke won about 450,000 more votes than Cruz. It’s a shocking turnaround from 2012 when Cruz had a 200,000-vote lead in those counties.

O’Rourke pulled it off by winning Tarrant and Dallas counties while dramatically cutting into the Republican advantage in Collin and Denton counties to the north. Around Austin, O’Rourke won not just Travis County, but picked up bordering Hays and Williamson too — something no Democrat has done in any of the last four U.S. Senate races in Texas. And in San Antonio, O’Rourke won Bexar County by more than 100,000 votes.

For Cruz, a major part of countering O’Rourke’s wins along I-35 was the 13-county Texas Panhandle. While none of those 13 counties has even 50,000 votes, when combined they became a potent one-sided region in Cruz’s back pocket.

O’Rourke had hoped to chip into those margins with his much-hyped travels to all 254 Texas counties. O’Rourke often talked on the campaign trail of meeting with people in the Panhandle and understanding their issues. But ultimately, Cruz defeated O’Rourke in those 13 counties with 80 percent of the vote. That gave Cruz a 70,000-vote margin of victory in the Panhandle, critical to offsetting O’Rourke’s successes.

Cruz almost predicted that result last week while campaigning in Pampa, in Gray County, just miles from the Oklahoma border. He warned more than 1,000 supporters at a rally that liberals were going to show up in droves in places like Austin and he needed them to do the same.

“We need the good people of the Texas Panhandle to stand up for common sense values and keep Texas bright, bright red,” Cruz said.

Video: Ted Cruz and Beto O’Rourke on Texas values

Almost as important for Cruz was Northeast Texas. Cruz made frequent stops in places like Tyler, Texarkana and Longview where he also was advertising early and often in the campaign. The payoff was clear on election night. In Smith County, where Tyler is the county seat, Cruz won about 70 percent of the 77,000 votes cast — nearly identical to his haul in 2012.

In some counties in East Texas, Cruz’s margin of victory actually increased over 2012.In Cass and Bowie counties, which border Arkansas, Cruz won 74 percent of the vote, 8 percentage points better than his first campaign.

Six of the larger counties in East Texas combined to provide Cruz with another 80,000-vote margin of victory.

Even as he survived O’Rourke’s push and the so-called Blue Wave, Cruz acknowledged the intensely competitive election was something he and other Texans are not used to seeing.