New York gubernatorial candidate Cynthia Nixon and two-term Gov. Andrew Cuomo face off in Thursday’s Democratic primary. (J. Conrad Williams Jr./Newsday/AP; Evan Agostini/Invision/AP)

Gov. Andrew M. Cuomo had a problem: He couldn’t settle on a nickname for President Trump.

At a Saturday rally on Long Island, Cuomo first labeled the president “Mr. Tough Tweeter,” a bully who “cowered to the NRA.” Then he was “Mr. Macho Man,” who was afraid of New York’s diversity. Finally, he became “Macho Man Mr. President Tough Tweeter,” whose bluster did not scare the two-term governor of New York.

“He’s a big man on the other side of a Twitter account,” said Cuomo. “Let’s see how he is in person.”

Cuomo has thrived in part by positioning himself as the president’s mocking foe, answering a demand by party activists, and is likely to ride that to the Democratic nomination for governor in Thursday’s primary.

But the messiness of his expected win demonstrates the political upheaval in his state — upheaval that in a federal primary in June claimed Rep. Joseph Crowley, the top House Democrat in New York.

Cuomo’s campaign to defeat challenger Cynthia Nixon has suffered from stumbles, from a party-funded mailer linking the challenger to anti-Semitism to a rushed ceremonial opening for a bridge named after his father, former governor Mario Cuomo — hours before engineers temporarily closed part of it due to safety concerns. What had been a show of political strength, with Hillary Clinton taking the stage next to the governor, transformed into a story of misused clout.

While that story may fade, Cuomo has had to contemplate a new Albany where Democratic insurgents may replace some of his political allies.

Cuomo’s lieutenant governor and his preferred nominee for attorney general are facing primaries against left-wing challengers.

Cuomo dismantled the Independent Democratic Conference, eight senators who voted to keep Republicans in charge of the state Senate, after liberal anger at the arrangement boiled over, but all of them are facing challengers, some backed by Sen. Kirsten Gillibrand (D-N.Y.) and other Democrats who see where their party is heading.

Zellnor Myrie, one of the “anti-IDC” candidates who’s attracted mainstream party support for his campaign, began as a hopeful insurgent; by this past weekend, he was in a Brooklyn bar listening to Reps. Yvette D. Clarke (D-N.Y.) and Nydia M. Velázquez (D-N.Y.) explain why they were backing him over a veteran IDC member.

“We’re going to come in with a progressive mandate,” said Myrie. “That’s going to change the machinations in Albany.”

For years, those machinations largely benefited Cuomo — if not always Democrats. When he took office in 2011, defeating a right-wing Buffalo businessman by 30 points, Cuomo said he’d improve the state economy even if it meant bucking the labor unions that endorsed him.

“I’ve played with them; I’ve played against them,” Cuomo said before the election.

With Republicans in command of the state Senate, Cuomo slashed projected spending on health care and education while lowering most income taxes. He delivered for liberals on social issues — he legalized same-sex marriage and signed the sort of gun laws that have won him endorsements years later.

That was not nearly enough for the left, whose prominence has grown dramatically in recent years, as the candidacy of attorney general candidate Zephyr Teachout demonstrates.

In 2014, Teachout launched a no-hope primary campaign against Cuomo, arguing that his deals with Republicans had smothered the Democratic agenda. Cuomo fought back and secured the party’s endorsement.

“The only issue was how dangerous it was to be seen near me,” recalled Teachout in an interview this week.

Four years later, Teachout’s challenge looks like the opening shot of the left’s insurgency. She won 34 percent of the Democratic primary vote and carried much of rural Upstate, in part because of her campaign against fracking — which Cuomo banned shortly after he won reelection.

Cuomo did not invest in electing a Democratic state Senate and did not dismantle the moderate Democratic conference — both campaign promises — until this year, after the Republican-run Senate passed a budget. His approach, however, has gained him broad support among voters.

The result has been a strangely bifurcated primary, with Democratic voters largely backing Cuomo while they flirt with electing more left-wing candidates to change how he governs. Cuomo’s own $25 million primary campaign is the juggernaut many Democrats expected, emphasizing his fights against Trump and the National Rifle Association and portraying Nixon as a naif seeking a job too big for her.

The strength of Cuomo’s message was evident in Westbury, where more than 100 voters — and rows of elected officials — piled into the “Yes We Can” rec center, opened six years earlier by Cuomo himself. As they waited to hear the governor, Jon Bon Jovi’s voice poured out of a sound system, asking “Who’s gonna work for the working man?” In interviews, voters veered between polite dismissal of Nixon’s challenge and contempt that she would try to unseat their governor.

“I’m so insulted by her lack of qualifications,” said Lisa Broughton, 55, a clean-energy specialist who wondered if Nixon even understood her industry.

“I think she makes a lot of good points, but Cuomo’s done a good job, and she has said she’d raise property taxes,” said Gail Gertrude, 65. “I have younger nieces and nephews who can’t afford to buy homes right now.”

Nixon, who in ads and stump speeches notes that the polling has badly missed upsets all year, has not conceded anything to Cuomo. But her campaign has increasingly emphasized the insurgents running up and down the ballot — especially Teachout.

At a Friday fundraiser at a bar in Manhattan’s Chelsea neighborhood, Nixon urged supporters to get behind the “uncorruptible” Teachout and other “people like me, who are not accepting a dime of corporate money.”

That included Jumaane Williams, the New York City Council member who is challenging Lt. Gov. Kathy Hochul from the left — and who won his first race by ousting a Democratic incumbent. On Monday, both he and Teachout were endorsed by Sen. Bernie Sanders (I-Vt.), who had appeared with Cuomo in January 2017 to promote a college tuition initiative and has stayed out of the governor’s race this year.

In an interview after Saturday’s unity rally, Williams said that while he was running on a quasi-ticket with Nixon, if he served with Cuomo, he’d consider it part of the job to check him.

“Most lieutenant governors believe their job is to be the eyes and ears of the governor; I believe it’s to be the eyes and ears of the people,” Williams said. “When the lip service is not backed up by action, I want to sit with the governor and correct that — and if they can’t, the people need to come first.”

Cuomo’s support for Hochul and Letitia “Tish” James, the Democrats’ endorsed candidate for attorney general, is reflected in TV ads that promote the entire ticket; but he has also won endorsements that have escaped his running mates.

The race for attorney general might have the greatest impact on Cuomo’s prospective third term. Teachout, who won Cuomo’s support in a 2016 bid for Congress, is now running explicitly as the candidate who would investigate his administration — and not just Wall Street and the Trump administration.

In TV ads, which portray Teachout as a lecturer in a classroom, the Trump administration’s “corruption” is front and center. On the stump, Teach­out expands the spotlight to cover Cuomo, reminding voters that she once ran against him and blistering him for creating and then closing — after it made some recommendations — a public-corruption commission.

Last week, at a rally that could not have differed more from Cuomo’s, Teachout said developers and business interests had bought the state and its governor away from its citizens.

“As attorney general, I will investigate, and I will prosecute, and I will look into all accounts,” Teachout said. “You know I will, because I’ve always been independent of the governor.”