NASHUA, N.H. — A steady stream of anxious Democratic voters went to the polls in this pivotal state Tuesday saying they'd chosen a candidate only in recent days or even hours, underlining Democrats' deep-seated frustration and uncertainty over how to defeat a president they revile.

Terry Heinzman, walking into a Manchester precinct, surprised herself by voting for former vice president Joe Biden. Just hours earlier, she had been trying to decide between Sens. Amy Klobuchar (D-Minn.) and Elizabeth Warren (D-Mass.).

“I thought it was going to be Amy or Elizabeth,” Heinzman said as she put on an “I voted” sticker. But as the retired event planner, 74, entered her polling place at the McDonough School, she decided that reversing what she saw as the calamitous damage of the Trump era required a more experienced hand.

“As much as I am progressive, in my values and the way I think this country ought to go, I don’t think it’s time right now,” Heinzman said. “I think there’s so much cleaning up to do.” Yet, asked whether Biden could beat Trump, she said, “I’m not sure anybody can, to be perfectly honest with you.”

That fatalism was widespread among voters in the first-in-the-nation primary, even after a year of campaign by a Democratic field that at one point included more than two dozen contenders. Linda Ryan, a 62-year-old teacher who voted in Nashua, also agonized until the 11th hour, saying, “I didn’t decide until yesterday.”

Ryan had been torn between Klobuchar and Buttigieg, finally choosing the former because “I just think she’s more electable.”

New Hampshire has played an outsize role in shaping previous presidential primaries, but Democrats fretted that the outcome this year would provide little clarity. The New Hampshire primary came a week after the botched Iowa caucuses that produced a delayed, muddled result.

“The truth of the matter is, tonight is likely going to raise more questions than answers,” said Karine Jean-Pierre, a Democratic strategist and senior adviser at MoveOn.org. “After tonight, less than 600,000 people will have voted. More than twice that many people will ride the New York City subway home tonight.”

Some campaigns also suggested the muddle was likely to continue. Warren campaign manager Roger Lau wrote to supporters Tuesday, “No candidate has come close yet to receiving majority support among the Democratic primary electorate, and there is no candidate that has yet shown the ability to consolidate support.”

For his part, Biden — who led the national polls for much of the past year — planned to leave New Hampshire early to head to South Carolina, a reflection of his poor prospects in the Granite State, where Sen. Bernie Sanders (I-Vt.) led the latest polls. Before departing, Biden pronounced himself “mildly hopeful” about New Hampshire — a slight improvement over an earlier assertion that he would “probably take a hit” there — and signaled his hope for a rebound in South Carolina.

Still, voters in New Hampshire grappled with their decision, saying Democrats across the country were looking to their state for guidance after the Feb. 3 Iowa caucuses were plagued by technical difficulties. In the end, both Sanders and former South Bend, Ind., mayor Pete Buttigieg declared victory in Iowa.

The turbulence led to a highly unusual inability by voters Tuesday to choose candidates until they absolutely had to. Preliminary exit polls suggested that nearly half of voters made their decisions in the past few days. That is considerably higher than the 36 percent of Iowa Democrats who made their decisions in the days before last week’s caucuses.

It’s also roughly double the percentage of New Hampshire voters who decided in the days before the 2016 primary, a contest that had been effectively narrowed to Sanders and Hillary Clinton.

The exit poll, conducted by Edison Media Research for the National Election Pool, The Washington Post and other media organizations, only underscored how undefined and unpredictable the Democratic race has been.

Donald Sanborn, who voted Tuesday in Merrimack, had been undecided between Buttigieg and Klobuchar, both seen as more-moderate alternatives to Sanders. He ended up choosing Klobuchar because he was impressed by her performance at a recent debate. “She was just so calm and knowledgeable,” he said.

Brian Murphy, 47, who voted for Warren in Portsmouth, said that while he was excited by several of the candidates, he longed for one who combined several of their qualities. “I wish we could build them all into one giant candidate that can beat the beast,” Murphy said, meaning Trump.

The president, who was in New Hampshire on Monday for a rally, presents a formidable challenge for Democrats in part because his party is unified behind him while the Democratic field remains fractured. In New Hampshire’s Republican primary, Trump faced only nominal opposition from former Massachusetts governor Bill Weld.

Democratic activists and officials were also shaken by the turnout in Iowa, which had fallen below their expectations, raising questions about whether the party’s candidates had sufficiently energized the electorate.

“The turnout in Iowa should have every Democrat concerned — it was a disaster,” said Jean-Pierre. “We will not beat Trump unless we get turnout up.”

Sanders, who boasts of his ability to attract new voters to his presidential run, acknowledged Tuesday that turnout in Iowa had not been as high as he wanted but cited an increase in the number of young voters as an encouraging sign. He touted the 7,500 attendees at his Monday-night rally in Durham, tweeting that it was it “the largest New Hampshire rally of any candidate in this primary.”

One presidential hopeful who was not on the ballot in New Hampshire also loomed large Tuesday: former New York mayor Mike Bloomberg.

The billionaire candidate has spent more than $300 million on his campaign, targeting states where voting is to take place beginning next month. By skipping the early states, while dominating television ad spending in places where other Democrats have not yet focused, Bloomberg has disrupted the usual nominating process.

At least a few New Hampshire voters opted to side with Bloomberg even though he was not on the ballot. Bloomberg received three write-in votes in the small community of Dixville Notch, whose five residents cast their votes just after midnight Tuesday in a long-standing tradition.

Bloomberg’s rise in the polls has sparked increasing attacks from other candidates, who have been highlighting his record spending. “I don’t begrudge his wealth, but I do begrudge a billionaire thinking he can buy the election,” Sanders said in an interview with “NBC Nightly News.”

But even the impassioned messages of candidates such as Sanders left large numbers of Democrats undecided when they arrived at their polling places Tuesday.

Tom Cerone said he was torn between Buttigieg and Sen. Michael F. Bennet (D-Colo.) until he got to the school in Merrimack where he was to cast his vote.

“I was gonna do Bennet,” Cerone said. “And then I said, ‘You know, he’s so low in the polls, let me get to Pete.’ ”

Dan Balz, Matt Viser, Chelsea Janes, Sean Sullivan, Emily Guskin, Dan Keating, Scott Clement and Felicia Sonmez contributed to this report.