Liberal activists across the country are eager to harness the energy of the Trump resistance to push the Democratic Party to the left on core social and economic issues, particularly before the party chooses its next presidential nominee in 2020.

But first they must figure out what went wrong Tuesday in Illinois.

That was the day an army of liberal groups and activists who had converged on the Chicago suburbs to engineer the primary defeat of an antiabortion Democratic congressman, Rep. Daniel Lipinski, and replace him with a candidate more suited to the deep-blue district, instead watched Lipinski notch a win.

In the days since, some on the left have consoled themselves with the notion that the candidate they rallied behind, Marie Newman, had never run for office. It is hard for anyone — even a hardened candidate — to unseat a congressman in a primary election.

But there are harsher explanations, as well — ones that carry meaning for liberals as they try to broaden their influence in this year’s midterm elections and beyond.

Newman, who described Lipinski as a “Trump Democrat” with “hate in his heart,” was no doubt echoing the anger that many on the left feel, but in doing so, she may have alienated many of the voters she needed to inspire to her side.

“It certainly was not the way I recommend a race be [run],” said Rep. Mark Pocan (D-Wis.), a co-chairman of the House Progressive Caucus and one of five Democrats to back Newman over their colleague. “People want to actually like the person they are going to vote for.”

Newman campaigned as though she viewed left-wing suburban politics as the future — and she counted on voters seeing it that way. In speeches and interviews, she said she was “running with the district,” and referred to polling — not every candidate does that — to prove that her issues were popular. On Saturday, millions are expected to march in favor of gun-control, an issue that Newman had worked on as a spokeswoman for Moms Demand Action.

But the tumult that ousted Republicans during the Obama years and drove Republicans to the right on immigration and environmental issues is not being repeated on the left. Lipinski, who proudly touted his “F” rating from the National Rifle Association, offered just enough Democrats a trustworthy brand and some coherence on their issues.

“Newman was trying to galvanize the progressive vote in the district, and I think her judgment was that stridency was the way to affect that,” said David Axelrod, a Chicago-based strategist for Obama’s campaigns. “I wouldn’t make that a template moving forward.”

Whose template was it? Newman did not run against Lipinski as a superior legislator. She ran as an avatar for a new suburban politics: pro-abortion rights, pro-gay rights, pro-immigration and, above all, for government investment in social welfare. Her biggest early boost came when three chapters of Indivisible, a liberal lobbying group, endorsed her.

The focus on a race outside of Chicago’s urban center, in an upscale, heavily white congressional district, represented a quantum leap of sorts for many on the left. Sociologists Lara Putnam and Theda Skocpol, writing in the liberal journal Democracy, have identified the leftward trend in the suburbs, saying it is growing “farthest and fastest outside of the metropolitan cores where local Democratic Party patronage structures still persist.”

The activist surge has surprised some state Democratic organizations, those with sturdy machines and those that had petered out. But the activists, brimming with idealism, have sometimes let it work against them. Newman’s friendlier critics say that happened in her race, days before the vote. With early voting underway, and with Lipinski fighting off her primary challenge, Newman’s campaign staff formed a union.

Newman’s political endorsers questioned the timing. Some worried that the time spent forming a union was time not spent getting out votes. Rep. Jan Schakowsky (D-Ill.), who had broken with her party to endorse Newman, mobilized her own campaign team — she faced no primary in her safe North Shore district — and vans full of canvassers sped down Interstate 90 to help out.

Together with Newman’s team, they nearly pulled it off. Newman fell just 2,124 votes short of beating Lipinski, according to the most recent Associated Press vote count. From election night on, her supporters described the defeat as a temporary setback. Schakowsky described it as a setup for wins to come.

“People thought for a long time that the machine in that district was invincible,” Schakowsky said. “What we absolutely showed was that it is not.”

Lipinski won precincts in the city of Chicago by a landslide, a victory for that rattled but resilient Democratic Party machine. But Newman won the suburbs, in a race her supporters were happy to describe as the party’s past against its ideological future.

Lipinski was a natural target because his district seemed impossible to lose. Republicans had abandoned their own candidate in the race, a white supremacist denounced by the party. Donald Trump had won just 39.9 percent of the vote in the district and had grown less popular since then.

When Lipinski bemoaned the “tea party of the left,” Newman’s supporters asked what the problem was; the tea party movement had won. In a January fundraising email for Newman, Ilyse Hogue, president of NARAL Pro-Choice America, described the Lipinski district as safely blue, implying that Democrats had to police their ranks just as Republicans had policed and purged theirs.

“With the GOP becoming more and more ideologically extreme in its opposition to abortion rights,” she wrote, “we simply can’t afford to let anti-choice Democrats off the hook.”

But Lipinski got off the hook. One reason, campaign veterans and endorsers say, was that the party’s voters are more heterodox than their party.

Quade Gallagher, an organizer with the Newman-backing group Reclaim Chicago, said that canvassers had long conversations with voters, sounding them out and trying to sell Newman’s candidacy based on the issues they cared about. To their surprise, some Democratic voters remained personally conservative and apparently responsive to attacks that Newman was not supportive of religion.

“At one door, we heard that Marie Newman wanted to jail nuns,” Gallagher said. “That was obviously a fabrication.”

Newman’s supporters said that her toughest opponent had been time. Some national groups backed her early, but most local Democrats assumed she could not win. Emily’s List, which exists to elect women who support abortion rights, did not endorse Newman until six weeks before the primary. Lipinski had done nothing to anger municipal labor unions, so they never considered his opponent.

“Look, this was a Democratic primary, and critical forces in the labor movement stayed with the incumbent,” said Rep. Luis V. Gutiérrez (D-Ill.), who endorsed Newman. “The labor movement needs to have a conversation between members who are making $40, $50 an hour going up against members who are making less than minimum wage.”

In the wake of Newman’s defeat, liberals are still poring over goals for 2018 and targets for 2020. Just three House Democrats voted for a ban on abortions after 20 weeks of pregnancy when Republicans introduced it this year. Just two — Lipinski and Rep. Henry Cuellar (Tex.) — represent districts that voted for Hillary Clinton in the 2016 presidential election.

In an interview, Cuellar dismissed the groups that backed Newman, saying they had “no clue” about what voters wanted in districts like his. He had won his seat by beating a more liberal Democrat and held off that same Democrat in a rematch.

“They came after me twice, and I beat ’em,” Cuellar said. “LBJ used to say: What’s the difference between a cannibal and a liberal Democrat? Cannibals don’t eat their own.”

Mark Guarino and Sean Sullivan contributed to this report.