SACRAMENTO — It was supposed to be a defining battle for the Democratic Party’s future, Cali­fornia’s Sen. Dianne Feinstein against her party’s fired-up activist left. Amid predictions of a Democratic civil war, one of the state’s largest labor unions endorsed her opponent and urged voters to reject “establishment politics.”

Yet days before Tuesday’s top-two primary, Feinstein is cruising toward what even her field of opponents acknowledge will be a giant victory. Her best-known opponent, state Sen. Kevin de León (D), who charged into the race last year on a message of generational change, has found himself ­challenged by a little-known ­Republican for the second spot in the November runoff, as lesser-known liberals fracture the anti-Feinstein vote.

Feinstein has bent the race her way by portraying herself as a reliable liberal in the Senate minority — and by moving further left and co-opting issues key to the state’s Democrats. And as she prepares to turn 85, she has allied herself with the party’s young activists.

In the campaign’s final stretch, Feinstein has run as an opponent of the death penalty and a defender of the state’s marijuana industry, new stances that have cut off lines of attack by de León, while drawing no perceptible backlash for their timing.

“I don’t want to not grow. I don’t want to not learn,” Feinstein told reporters last week at a roundtable on the Trump administration’s proposal to block federal funding of Planned Parenthood. “The world changes. We change. I think that’s what should make me an attractive senator, particularly to young people.”

The senator’s frustrated opponents say the real fight will take place in November.

“If I do get into the runoff, it changes the complexity of the campaign,” de León said in an interview at an office near the state capitol. “When I engage with voters, up and down this state, everyone — all social and economic classes — believe it’s time for a change.”

But nothing in the race so far has borne out his optimism. Indeed, the campaign has proved anew the difficulty of dislodging a well-regarded incumbent in a far-flung state where it takes years and millions of dollars to become known to voters. The very thing that de León implicitly criticizes — a Senate tenure that has stretched from late 1992 — has helped to cement Feinstein’s substantial ­advantage. A beneficiary of the first Year of the Woman in 1992, Feinstein is poised to gain from a second wave of women’s activism this year.

The party’s left, invigorated since the 2016 presidential campaign, had hoped for something more than a long-shot runoff. In town halls in Northern and Southern California last year, Feinstein was heckled as insufficiently liberal by opponents who made thinly veiled arguments that she had grown old and out of touch.

De León, 51, has been careful not to directly discuss Feinstein’s age, but he has drawn attention to her long tenure and her “50 years” in politics.

Feinstein has quieted questions about her faculties with long editorial board interviews and short but active campaign stops.

“I think I’m in pretty fair shape,” Feinstein said Thursday. “I’m just going to keep going.”

De León, who had hoped to cast himself as the true liberal and Feinstein as an opportunist, has struggled to break through. In media interviews, de León has questioned Feinstein’s commitment to the state’s burgeoning Latino population by saying she “made a career of attacking immigrants” before becoming a reliable vote for immigration reform.

In an interview, de León explained that attack line: Feinstein had been late in opposing Proposition 187, the 1994 ballot measure that cut off undocumented immigrants from public services.

“It took her until two weeks before the election to oppose 187,” de León said. “I was fighting it in the streets, getting spit on, getting epithets hurled at me.”

Yet most voters in the state favored Proposition 187, and in her current term, Feinstein has sided with her party’s left on every immigration issue before the Senate. And other issues Feinstein has championed — including her long campaign against assault weapons and her opposition to CIA abuses — have undeniably defined her as a liberal. Some Feinstein heresies, such as her vote to authorize the war in Iraq, have faded into the background.

Indeed, even Feinstein’s recent leftward shifts seem to have been accepted.

“Dianne’s name ID is high, but people don’t pay close attention to her positions,” said Garry South, a Democratic strategist. “The average voter doesn’t know what she said about the death penalty or immigration in 2000. If your main information about her is that she was mayor of San Francisco, you don’t know that she was seen as a conservative mayor — you assume she’s liberal.”

De León has fallen short in multiple ways: He failed in his effort to win the party’s endorsement, and he had raised just $1.3 million for his primary campaign as of the most recent fundraising report.

Feinstein, who had put $5 million of her own money into the campaign, had raised nearly $10 million on top of that.

The cash has given Feinstein plenty of room to renew acquaintances with an electorate that has sent her to Washington five times. In 2006, one of Feinstein’s reelection spots showed her watching one of her first TV ads alongside her granddaughter Eileen, and remarking on how much life had changed since. Feinstein’s 2018 campaign more pointedly has cast her as a loyal ally of the biggest — and youngest — movements in Democratic politics.

In one Spanish-language ad, Feinstein is seen sitting across the table from President Trump and challenging him at a White House meeting on the fate of immigrants who arrived in the United States as children. In an English language spot, Feinstein appears onstage at a “March for Our Lives” rally on gun control, with a narrator promising that “Dianne Feinstein and a new generation” could finally break through and deliver on gun-control measures.

De León, meanwhile, has hardly appeared on the air. Endorsements from the California Nurses Association and billionaire Democratic donor Tom Steyer did not come with much financial cover; the Nurses-funded PAC, A Progressive California, spent less than $1 million on pro-de León ads that ran on Los Angeles television stations.

There has been no paid advertising highlighting the attacks liberals wanted to make on Feinstein, from a 2017 quote in which she suggested “patience” in opposing Trump to her refusal to co-sponsor the Senate’s main universal health-care bill.

Steyer, who had briefly considered his own run for the Senate, has focused instead on funding campaigns to flip Republican-held House seats in districts that backed Hillary Clinton for president. On Saturday, as de León campaigned around Los Angeles, Steyer attended a get-out-the-vote rally for an Orange County Democrat facing a Republican-backed recall. There, Steyer said he “hopes” de León makes the runoff, “but I don’t know what the numbers are.”

Feinstein’s liberal opponents insist there will be time and money to make the case against her during the five months before a possible runoff between the senator and de León. But pre-election polls have cast doubt about whether de León will make the ballot, with a political unknown, Republican James Bradley, close behind him.

Divisions among Democrats have also hurt de León. His effort to push a universal health-care plan through the state Senate — a measure with no funding mechanism that opponents said would balloon the state’s budget — irked some in his party. Opponents in the campaign include Alison Hartson, a liberal activist who has portrayed de León as an “establishment” Democrat.

“He was getting ready to run for lieutenant governor before he ran for Senate,” Hartson said in an interview. “When he was doing that, 75 percent of his donations were coming from corporations.”

De León has dismissed Hartson and another challenger as spoilers; in an interview, he alternately referred to Hartson as “Alison Hartley” and “Alison Hartman.” Everything can change, he argued, if he gets to face Feinstein in November, although some of his allies are lowering expectations.

“I am hoping de León makes it or one of the other Dems does, and we don’t have a Republican squeak through because the progressives split the vote,” said Rep. Ro Khanna (D-Calif.), one of a few members of Congress who have backed de León. “I do think more progressive energy will flow to de León in the top two, but the primary focus will be taking back the House in California.”

On Thursday, as de León rushed to a vote in the state Capitol, he paused to point to a wall of portraits showing everyone who’d preceded him as state Senate president.

“White guy, white guy, white guy, white guy, white guy, white guy, and then, me,” he said.

But he has some distance to go to convince voters that he should supplant Feinstein, who has emphasized identity politics of her own. At the Planned Parenthood event, Feinstein pointedly called for more women to run for office, and she posed for photo after photo with activists and candidates.

“Hearing what she’s done for women has been really inspiring,” said Karina Talamantes, 29, a candidate for Sacramento County’s board of education. “Women make up just 20 percent of elected officials, and having women support women is really important to me.”