Former Vice President Joe Biden won Tuesday’s Democratic presidential primary in Texas, The Associated Press reported early Wednesday morning.

It was by far one of the closest races of the night, remaining neck-and-neck between him and Sen. Bernie Sanders (I-Vt.) for several hours after the polls closed.

Texas, one of 14 states to vote for Democratic candidates on Super Tuesday, awards 228 delegates, making it the biggest trove of the night after California.

Biden’s campaign upset expectations, carrying it on the strength of a three-day earned media blitz in which Biden’s onetime moderate rivals coalesced behind his candidacy. Polling that had once shown Sanders holding a modest lead over Biden in Texas began shifting following Biden’s dramatic win in South Carolina on Saturday.

Of all the endorsements Biden picked up in the interim, the blessing of former Rep. Beto O’Rourke, a short-lived presidential candidate whose 2018 run for Senate nearly ousted Sen. Ted Cruz (R), was likely the most significant pickup in Texas.

O’Rourke joined Biden at a rally in Dallas on Monday night. The former vice president promised that O’Rourke, who made tougher gun laws a trademark of his presidential bid, could play a role in the development of his gun safety policies.

Call it a W. Thank you, Texas. pic.twitter.com/iXFI1ys9wi — Joe Biden (Text Join to 30330) (@JoeBiden) March 4, 2020

“We won Minnesota because of [Minnesota Sen.] Amy Klobuchar. And we’re doing well in Texas because of Beto O’Rourke,” Biden said in a victory speech in Los Angeles on Tuesday night.

Biden’s rally in Texas was part of a last-minute swing through the state that ended up focusing on major metropolitan areas with large blocs of Black voters ― a demographic with whom he enjoyed popularity in Texas even before his big South Carolina win. In addition to Dallas, the other stop on his tour on Monday was Houston, which also has a large Black population.

As in other Super Tuesday states, the series of Texas-focused endorsements and rallies managed to propel Biden beyond competitors who had invested far greater resources in developing campaign infrastructure in Texas.

Dollar for dollar, the Biden rival who got the least value for his investment was likely former New York Mayor Mike Bloomberg. Apparently knowing he was poised to underperform, Bloomberg spent the day in Florida, where voters aren’t due to head to the polls until March 17. He swatted away the suggestion that his presidential bid was hurting Biden’s chances, claiming instead that Biden was taking votes away from him. (By Tuesday night, as Bloomberg’s disappointing results poured in, it emerged that he is reassessing his campaign’s future on Wednesday.)

But though the full details of the delegate math have yet to emerge, Biden’s win in the state is especially disappointing for Sanders, whose strong polling position in Texas and much-touted strength with Latino voters appeared to put the state within his reach.

The Sanders campaign maintains that it has had an operation on the ground in Texas longer than any of its rivals.

But until very recently, that operation was very grassroots ― consisting almost entirely of networks of thousands of volunteers knocking on doors and hosting events independently. The campaign began airing television ads in the state in February and opened up field offices in mid-February. The campaign’s treatment of Texas is a stark contrast with California, where the Sanders campaign had built a robust operation dating back to the summer.

Sanders’s aides nonetheless saw in Texas a chance to replicate its success at reaching ― and appealing to ― Latino voters. Latinos make up an estimated 40% of Texas residents ― a fraction of a percentage point higher than in California.

Texas is a challenging state for any campaign, since it consistently has among the lowest voter turnout in the nation. And the state’s Latinos ― some of whom are ineligible to vote either due to their young age or lack of citizenship ― tend to have lower voting rates than the overall population.

Prior to Super Tuesday, though, Chuck Rocha, a Mexican American raised in Tyler, Texas, cast it as the perfect testing ground for the Sanders campaign’s long-promised ― and as yet unproved ― conceit that it stood to benefit from expanding the electorate.

“It was great in Nevada and we shocked the world, but, really, people have been working for generations to turn out Latinos in Texas, and we’re going to show them that it can be done,” Rocha told HuffPost.

As the campaign did in Nevada and Iowa before that, it introduced Sanders in television ads and mailers as the son of an immigrant father. Rocha and his team then ensured that they disseminated Sanders’s standard message about fighting for “Medicare for All,” a $15 minimum wage and free college tuition on the right channels, using the right languages ― a formula Rocha calls a matter of “cultural competency.”

For example, the campaign spent more than $1 million on Spanish-language television ads alone across the state, targeting areas such as South Texas, where residents are more likely to be primarily Spanish speakers. In East Texas, where Rocha grew up, Latinos are more likely to be English speakers or bilingual, and they received more bilingual materials.

Mike Blake/Reuters Former Vice President Joe Biden addresses supporters at his Super Tuesday night rally in Los Angeles. He appeared to gain an eleventh-hour lead in Texas.

In the U.S.-Mexico border city of Laredo, a hotly contested Democratic primary in which attorney Jessica Cisneros was taking on conservative Democratic Rep. Henry Cuellar anchored a ticket where Sanders was vying with Biden for dominance.

Though some residents voting for Cisneros told HuffPost they were voting for Sanders, who endorsed Cisneros, it was not always the case ― nor was it always the case that Sanders voters all backed Cisneros. Regardless, Sanders appeared to enjoy significant support.

“I like the way he stands up for ordinary people ― the way he talks about the change he wants to make in the U.S.,” said Mike Segura, an oil rig mover who voted for Sanders at Santa Niño Elementary School. Segura said he was unsure about how to vote in the congressional race so he left that part of the ballot blank.

Flor Renovato voted for Sanders at the same school, seeing in his promises of Medicare for All and plans for a more compassionate approach to criminal justice and immigration, the closest approximation of her “morals.”

But Renovato was also excited about Cisneros’s candidacy, seeing it as part of the same movement for progress, and she was disappointed that Sanders did not visit the district to campaign for her.

“Him coming down here would have increased his support from Laredoans as well,” she said.