Republican Pete Flores' upset victory in a Democratic-friendly Texas Senate district Tuesday night has spurred GOP jubilation and Democratic soul-searching with less than two months until the November elections.

"All this talk about a 'blue wave'? Well, the tide is out," Republican Lt. Gov. Dan Patrick proclaimed at Flores' election night party in San Antonio.

Flores beat Democrat Pete Gallego, a former U.S. representative, by 6 percentage points in the special election runoff for Senate District 19, where state Sen. Carlos Uresti, D-San Antonio, resigned earlier this year after 11 felony convictions. The win made Flores the first Hispanic Republican in the Texas Senate and grew the GOP majority there to 21 members, a key addition as the caucus heads toward November looking to retain its supermajority.

Democrats moved quickly Tuesday night to blame Gov. Greg Abbott for scheduling the special election at a time when turnout was expected to be low and would favor his party. But they were nonetheless demoralized Wednesday, trying to figure out how they let a valuable seat flip in a district where Uresti repeatedly won re-election by double digits and that Hillary Clinton carried by 12 in 2016.

Gallego's campaign said that at the end of the day, it was not able motivate its voters as much as Flores did.

"Our investment was in the grassroots and trying to increase the number of Democratic voters in the densest precincts where people hadn’t turned out and trying to cut through the clutter of all the other campaigns going on targeting November ... and it proved to be a lot more difficult to get people tuned in to the fact that an incredibly important race was happening today," Gallego strategist Christian Archer said.

The relative enthusiasm for Flores was evident in the district's biggest Republican counties — places like Medina County, where he routed Gallego with 80 percent of the vote. Flores' margins in the red counties were more than enough to offset Gallego's advantage in vote-rich Bexar County, which gave Gallego a modest 54 percent of the vote.

Flores' campaign said it benefited from a number of factors throughout the race, starting with the deep Democratic divide that unfolded as Gallego battled state Rep. Roland Gutierrez, D-San Antonio, ahead of the eight-way July 31 special election. Gutierrez, who won Bexar County then, never endorsed Gallego in the runoff, and on Wednesday, the two sides had different accounts of how much of an effort, if any, Gallego made to court Gutierrez.

But Flores also had to prove himself within his own party and emerge as the consensus candidate on July 31, when two other, lesser-known Republicans were on the ballot. Flores pulled that off with just days to spare, earning late endorsements from a who's who of top Texas Republicans, starting with U.S. Sen. John Cornyn and then Patrick, U.S. Sen. Ted Cruz and Abbott.

"We knew that if we could get in the runoff, we’d have additional help because the stakes would be clear ... and the value of winning would be obvious," said Matt Mackowiak, Flores' consultant.

The 11th-hour endorsements helped propel Flores from third place in early voting to first place in Election Day ballots — and a decisive first overall on July 31. Still, Democrats insisted the district remained bright blue, noting their four candidates combined for 59 percent of the vote and the three Republicans netted 40 percent. In a statement on Election Night, Texas Democratic Party Chairman Gilberto Hinojosa said it was clear "working Texans are overwhelmingly choosing Democrats to represent their interests."

In the runoff, the high-ranking support proved vital — especially that of Patrick, who tapped his campaign account to the tune of nearly $175,000 to help Flores with mail, polling and ads. Gallego had some deep-pocketed donors, but nothing like the campaign machinery that Flores was able to import with Patrick's aid.

There was an also a united front of political action committees assisting Flores, including groups like the Associated Republicans of Texas and Empower Texans — two outfits that were bitterly at odds during the primaries and runoffs earlier this year. The anti-abortion group Texas Right to Life got involved especially early, running digital ads that sought to disqualify Gallego among socially conservative Hispanic voters in the district.

One of the biggest differences between the two campaigns was media spending. Flores got a significant head start on radio ads — beating Gallego to the airwaves by at least a week. And Flores went on TV, while Gallego never did. Archer defended that decision Wednesday, saying he did not view it as an effective use of money in a district like SD-19 compared to, for example, investing in an aggressive field program.

In their ads and elsewhere, the campaigns took divergent approaches to messaging. Gallego put forward a largely positive pitch about being the safe, reliable choice — "I Trust Pete" was the slogan — while Flores was not afraid to hammer attacks, airing radio and TV ads seeking to tie Gallego to Democratic congressional leader Nancy Pelosi.

Gallego's loss was not for a lack of money. While he depleted his campaign funds clashing with Gutierrez, he was able to replenish considerably and had much more cash on hand — $153,000 — than Flores did eight days out. That figure left some political observers wondering Tuesday night if he had left serious money unspent, but Archer said the campaign burned through the cash it had — as well as that which it raised — in the final days, ending the race with less than $15,000 in the bank.

The early voting period, which was from Sept. 10-14, held encouraging signs for Flores. Most of the biggest increases in early vote turnout over total turnout for the July 31 election occurred in counties where Flores had bested Gallego, according to an analysis by the website Texas Election Source.

At the end of the day, the race saw the largest percentage increase in turnout from a special election to a special election runoff in four years, according to the secretary of state’s office.

Still, Democrats pointed the finger at Abbott for calling the special election at a time that guaranteed there would be much lower overall turnout than if he had placed it on the November ballot. In an election night statement, Hinojosa, the state Democratic Party chairman, said Abbott "stole an election, plain and simple ... denying the people of West Texas and the U.S. Mexico border representation that shares their values."

Abbott spokesman John Wittman fired back in a statement: "When it comes to stealing things in SD 19, I’d expect that Texas Democrats, under the leadership of convicted felon state senator Carlos Uresti, know what they are talking about. However, the reason this was the biggest increase in turnout between a runoff and a special election in four years was because Col. Flores, whose life has been dedicated to law enforcement, focused on issues that matter to Texans."

With Flores, there are now 21 Senate Republicans, giving the party breathing room as it approaches the November elections with as many as three GOP seats in play. That means Republicans can lose two of those seats and still have the 19 members required to bring legislation to the floor without Democratic support.

The value of the SD-19 pickup was not lost on the caucus, which issued a first-of-its-kind unanimous endorsement of Flores about two weeks into the runoff.

"The Republican caucus has never had 21 members until today, so that’s a two-thirds majority," said state Sen. Paul Bettencourt, who chairs the caucus. "That’s a huge advantage on passing legislation like property tax reform."

Some Republicans also saw Tuesday night as a harbinger for the 23rd Congressional District, a perennial swing district that Gallego once represented in Congress and that overlaps much of SD-19. U.S. Rep. Will Hurd, R-Helotes, is fighting for re-election there in November against Democrat Gina Ortiz Jones, who was on hand Tuesday night as Gallego addressed his supporters.

"The Resistance collided with reality tonight in SD19," Jack Pandol, a spokesman for the National Republican Congressional Committee, said in a statement. "Nobody should be more worried about this Republican blowout than liberal Gina Ortiz Jones, whose chances in TX-23 are growing dimmer by the day."

Jones' campaign echoed other Democrats in saying Abbott scheduled the special election "to beat what's coming in November" — and dismissed the notion her chances had decreased.

"We’re seeing it on the ground every day on our campaign—voters are excited about opportunity, excited about change and excited to vote for Gina on November 6," Jones spokeswoman Noelle Rosellini said in a statement.

Disclosure: The Texas Secretary of State's Office has been a financial supporter of The Texas Tribune, a nonprofit, nonpartisan news organization that is funded in part by donations from members, foundations and corporate sponsors. Financial supporters play no role in the Tribune's journalism. Find a complete list of them here.