Illinois Gov. Bruce Rauner, shown last month, defeated his challenger in the Republican primary on Tuesday. (Reuters)

Illinois's embattled Republican governor, Bruce Rauner, narrowly managed to fend off a socially conservative primary challenger Tuesday, sending him into the general election as one of the most endangered governors in the nation.

Rauner beat state Rep. Jeanne Ives (R), a lawmaker who wasn't well known in the state until recently. The governor's narrow win highlights the fractures in the Republican Party between pro-Trump allies like Ives who demand more ideological purity and moderate blue-state Republicans like Rauner trying to stay afloat deep in Democratic territory. He led by just 2 to 3 points all night, and with 91 percent of the vote in, he was declared the winner by just 3.5 percentage points.

Rauner will face Democratic billionaire J.B. Pritzker, who also won his primary Tuesday, in what is shaping up to be one of the expensive nonpresidential elections in U.S. history. Rauner is a multimillionaire, and both candidates are pouring their own money into their campaigns.

But being outspent could be the least of Rauner's worries come November.

For one, he's running for reelection as a Republican in a Democratic state, a state that voted for Hillary Clinton by nearly 20 points. And he must make a compelling reelection bid after presiding over one of the worst modern fiscal crises of any state, which left Illinois without a full budget for two years, downgraded its credit rating to nearly junk status and made Rauner one of the least popular governors in America.

Pritzker will have plenty of help in trying to unseat Rauner: Democrats in Illinois — and Washington — are singularly focused on proving that Rauner's 2014 win in Democratic territory was a fluke.

Since Rauner took office in 2015, he's been squeezed between Democratic majorities in statehouses and an increasingly agitated his conservative base. He signed bills protecting abortion and immigrant rights, while failing to deliver on campaign promises to curb Democrats' power.

Establishment Republicans in Illinois feel like they averted a near disaster for their party on Tuesday. Ives's firebrand of politics may be popular enough to gain traction in a Republican primary, but they warned she could never win a general election in the home state of President Barack Obama. “A far-right socially conservative Republican does not win in this state,” said Pat Brady, the former chairman of the Illinois Republican Party and a Rauner supporter.

But Rauner allies also maintain they're not surprised that the governor had a strong primary challenge. The Republican Party, both in Illinois and nationally, is quickly moving to favor more Trump-style politics. The distinctions were clear in this primary: Ives embraced Trump as part of her campaign, while Rauner said he and the president are not “particularly close.”

Ives also had easy openings to attack Rauner from the right for signing bills that expanded publicly funded abortions to low-income women and that prevented officers from detaining people they suspected are undocumented immigrants, without a warrant.

He has betrayed, literally, the core values of the Republican platform,” she said shortly after she launched her campaign.

Rauner's challenge now is to calm his base while also convincing more centrist general election voters to give him a second chance. His allies say the most effective message could be presenting himself as he did in the first campaign: as a check on the Democratic powerhouses in the state. Rauner campaigned in 2014 as an outsider who was trying to clean up a state riddled with corruption; four of Illinois's last seven governors went to prison. That message — and Rauner's willingness to spend his own money to spread it — worked: He became the first Republican governor of Illinois in 16 years.

In some ways, he never stopped campaigning against Democrats. His singular target for the past four years — the villain he blamed for everything from budget battles to his failed attempts to install term limits — has been powerful Illinois State House Speaker Mike Madigan (D). Rauner went so far this December as to say that he wasn't in charge of the state, Madigan is. It was a comment that made some of his allies cringe, but Rauner didn't back down from it.

Attacking Madigan may translate nicely to a campaign strategy in the general election. Even Republicans who don't trust Rauner can get behind a candidate promising to be a thorn in the side of the powerful speaker, Brady said: “The one unifying thing that Republicans have in this state is their dislike for Mike Madigan.”

Another challenge Rauner won't have to worry about is money. The multimillionaire has already given $50 million to his own campaign in anticipation of Pritzker spending his own personal wealth to win. Insiders on both sides are bracing for a battle of wealthy titans trying to convince voters they're just an average guy who won't run the state even further into the ground than it already is.