Rhode Island Gov. Gina Raimondo (D), seen in January, won her party’s nomination for governor on Wednesday. (Steven Senne/AP)

Rhode Island Democratic Gov. Gina Raimondo survived a primary challenge Wednesday after a campaign that put the party’s internal battles on full display up and down the ballot in one of the year’s final nominating contests.

Raimondo defeated Matt Brown, topping the former secretary of state who ran on a platform styled after that of Sen. Bernie Sanders (I-Vt.) and who said that voters had a chance to replace the political establishment.

The governor advanced to a rematch against Cranston Mayor Allan Fung, who defeated state House Minority Leader Patricia L. Morgan and state legislator Giovanni Feroce in the Republican primary.

With 99 percent of the ballots counted, Raimondo had just over 57 percent of the vote to nearly 34 percent for Brown. Fung won 56.6 percent of the vote to 40 percent for second-place finisher Morgan.

The Democratic race was one of several contests pitting established incumbents against liberal challengers hoping to reshape the party’s identity. While Democrats dominate the state and hold supermajorities in its legislature, socially conservative Democrats hold the balance of power.

The battles that mirrored other intraparty competitions across the country over the past few months. Overall, the results have been mixed, with liberal firebrands winning in some races and more-moderate contenders prevailing in others.

Raimondo narrowly won her first term in 2014 and has struggled to unite her party since. A former state treasurer and venture capitalist, she has tried to build her campaign around an economic comeback; wage growth has picked up, and the state’s unemployment rate has dropped to 4.1 percent this summer from 6.8 percent in November 2014.

“Together, we will keep bringing the change Rhode Island needs,” Raimondo tweeted Wednesday night. “On to November!”

For most of the campaign, Brown struggled to raise money or attract attention — and Raimondo refused to debate him. But Brown’s supporters perked up when Raimondo, who has raised nearly $8 million for her reelection bid, began running an ad that called her challenger a “failed politician” who “stiffed his workers” in his previous major campaign, 10 years ago.

Brown pounced on the ad, threatening to sue and arguing that it revealed a governor on the ropes. But he was not Raimondo’s only challenger. Spencer Dickinson, a former state legislator also running to Raimondo’s left, was carrying about 10 percent of the vote, with more than 90 percent of ballots tallied.

On the Republican side, Fung’s win was no surprise. He was buoyed by his closer-than-expected 2014 defeat by Raimondo and by polls that showed him competitive with her in November. Raimondo begins as an early favorite to win reelection.

Liberal activists were also eying races for lower-profile offices on Wednesday. Lt. Gov. Dan McKee narrowly defeated Aaron Regunberg, a state legislator less than half his age who ran to the incumbent’s left.

Over the weekend, Regunberg won the endorsement of Sanders, whom he’d backed for president — and who won the state’s 2016 primary, powered by independent voters.

“Bernie moved us [to] think big, to imagine a system of government that works for everyone rather than one that’s rigged for the few,” Regunberg tweeted after the endorsement. “That’s exactly what we’re trying to create here in Rhode Island.”

McKee is not even among the state’s most conservative Democrats — all of whom are facing challengers.

State Sen. Frank A. Ciccone III a centrist Democrat, survived a challenger who ran to his left, while Paul V. Jabour, another moderate, lost his race. There was enough worry about upsets in those races that a new PAC, the Gaspee Project, had sent direct mail to defend them.

“Radical progressives like his opponent do not believe in America,” said one mailer supporting Jabour. “They believe in European-style socialism where the government controls our lives.”

Earlier this year, the party’s attempts to hold back the challenges backfired badly. Three liberal women, first elected in 2016, lost the party’s official endorsement and got it restored only after a national outcry.

On Thursday, the primary season will conclude with state races in New York.