Donald J. Trump and Senator Bernie Sanders of Vermont harnessed working-class fury to surge to commanding victories in a New Hampshire primary that drew energetic turnout across the state.
The victories by two outsider candidates dealt a remarkable rebuke to the political establishment, and left the race deeply unsettled.
Mr. Trump, the wealthy businessman whose blunt language and outsider image have electrified many Republicans and horrified others, benefited from an unusually large field of candidates that split the vote among traditional politicians like Gov. John Kasich of Ohio and Senator Marco Rubio of Florida.
But Mr. Trump also tapped into a deep well of anxiety among Republicans and independents in New Hampshire, according to exit polling data, and he ran strongest among voters who were worried about illegal immigrants, incipient economic turmoil and the threat of a terrorist attack in the United States.
The win for Mr. Sanders amounted to a powerful and painful rejection of Hillary Clinton, who has deep history with New Hampshire voters and offered policy ideas that seemed to reflect the flinty, moderate politics of the state. But Mr. Sanders, who has proposed an emphatically liberal agenda to raise taxes and impose regulations on Wall Street, drew support from a wide cross-section of voters who trust him more to address income inequality and expand the health care system.
Mrs. Clinton, who won the primary here in 2008, planned to huddle with her advisers on Wednesday to discuss possible changes in political strategy and additions of staff members, according to Democrats close to the Clintons. She also plans to discuss whether to mount new lines of attack against Mr. Sanders on Thursday night at their next debate.
While Mr. Trump has led in New Hampshire polls since July, and Mr. Sanders has been ahead for the last month, the wave of support for both men was nonetheless stunning to leaders of both parties who believed that in the end, voters would embrace more experienced candidates like Mrs. Clinton or one of the Republican governors in the race. Yet the two men won significant support from voters who felt betrayed by their respective parties and were dissatisfied or angry with the federal government.
By winning so handily, the brash New Yorker and the blunt Vermonter asserted themselves as political forces that their parties and their opponents must quickly reckon with.
On the Republican side, with Senator Ted Cruz of Texas winning the leadoff Iowa caucuses and Mr. Trump prevailing here, the political establishment is confronted with two leading candidates, running well-funded campaigns, who party leaders think will lose badly in a November general election. Their success in the two early nominating states suggests that a long, costly and unusually turbulent primary campaign will follow.
Mr. Trump’s candidacy, in particular, represents a potential takeover of a party in which he has scant ties. Leveraging celebrity and a ubiquitous presence across both traditional and social media, Mr. Trump has embraced a style of populism on trade, foreign policy and immigration closer to the European nationalist parties than to American conservatism.
He has never held elected office and was not even a registered Republican this time four years ago.
For the Democrats, Mr. Sanders’s popularity with liberals, young people, and some women and working-class white men has underscored potential vulnerabilities for Mrs. Clinton in the nominating contests ahead. She is now under enormous pressure to prove that her message can inspire and rally voters, and she has gone so far as to promise to rethink and adjust her campaign strategy in hopes of connecting better with Democrats, including women, whom she has long viewed as her base.
Mr. Sanders faces his own test to show that he can appeal to voters beyond the largely white, left-leaning electorates in Iowa and New Hampshire, and attract large numbers of rank-and-file Democrats.
Clinton advisers gritted their teeth Tuesday night as they dissected exit polls and other data to determine if Mrs. Clinton’s political vulnerabilities stemmed from the particular demographics of New Hampshire, which is overwhelmingly white, or if they reflected deeper unease. One troubling sign: Mr. Sanders was the choice, by a lopsided margin, among voters who said it was most important to have a candidate who is “honest and trustworthy.”
Several advisers to Mrs. Clinton said they were especially concerned about her support among women — the group that provided her margin for victory in the 2008 New Hampshire primary. The Clinton strategy depends on her beating Mr. Sanders among women and attracting large numbers of minority voters, like Hispanics in Nevada and African-Americans in South Carolina. Those states hold the next Democratic contests, later this month.
“A big win in Nevada is really important for her to show she represents the changing face of America and can build on that,” said Jim Manley, a Clinton backer and a former senior aide to Senator Harry Reid of Nevada, the minority leader. “Nevada and South Carolina are where she needs to regain her footing after New Hampshire.”
Both the Sanders and Clinton campaigns have built robust political operations in those next states, but Sanders advisers say momentum is on their side after the New Hampshire victory and a near-tie in the Iowa caucuses. Mr. Sanders is also hoping that his proposals for a $15 minimum wage and a breakup of big banks will find support in vote-rich Las Vegas and Reno, where many people earn low wages and lost homes to banks after the 2008 financial crisis.
A win for Mr. Sanders in the Feb. 20 Nevada caucuses would raise additional doubts about Mrs. Clinton.
“New Hampshire will have a real impact in Nevada for Bernie, and Nevada will have a real impact in South Carolina,” said Tick Segerblom, a Nevada state senator supporting Mr. Sanders.
But first Mrs. Clinton and her husband must shake off the New Hampshire loss, one of the most stinging of their long political careers.
The couple have been unusually attached to this state for decades: Bill Clinton stabilized his scandal-plagued presidential bid in 1992 with a second-place finish in the primary, and Mrs. Clinton made her own comeback in 2008 by winning here with 39 percent of the vote after losing the Iowa caucuses to Barack Obama.
This time around, the Clintons tried to diminish the state’s importance by arguing that Mr. Sanders had an advantage because he was from a neighboring state. But they campaigned vigorously all the same, and Mr. Clinton himself unleashed a lengthy, pointed attack on Mr. Sanders at an appearance on Sunday evening.
The defeat also powerfully captured the way that the Democratic electorate has changed since the Clintons held power in the 1980s in Arkansas; in the 1990s in the White House; and through early 2009, when Mrs. Clinton gave up her Senate seat in New York to become secretary of state. The party’s restive left wing is exerting much more influence, partly because of anger at the financial industry and establishment politics after the Great Recession. Mrs. Clinton, in turn, has always come across as a pragmatist more than a dreamer, and she rarely intones a vision of America that is broadly inspiring.
“That lack of idealism is what allowed Obama to beat her, and it’s giving Bernie room to grow,” said Dan Payne, a Democratic strategist in Boston who supports Mrs. Clinton.
The unaffiliated New Hampshire voters who participated in both party primaries, and who supported Mr. Trump and Mr. Sanders in sizable numbers, appear to have found those candidates’ anti-establishment messages to be an asset.
Merging politics and entertainment, Mr. Trump disregarded the time-honored New Hampshire traditions of lavishing personal attention on voters and offering them detailed policy proposals. Instead, he flew in and out of the state on his private jet when the weather cooperated, held raucous rallies, and won support by faulting immigrants who entered the country illegally for crime and job losses, proposing a temporary ban on Muslims to prevent terrorism.
He declared his independence from a reviled status quo by inveighing in blunt and occasionally vulgar terms about “stupid” leaders weakening America. And in appealing to his fellow Northeasterners, in one of the country’s most secular states, Mr. Trump was on hospitable political terrain. He may have held fewer events here than any other Republican candidate except Ben Carson, but his voters cared little.
Conversely, New Hampshire’s Republican leaders, who jealously guard their first-in-the-nation status, were as perplexed as they were horrified.
“By name, I only know five people supporting Donald Trump,” John H. Sununu, a former governor of New Hampshire, said Tuesday. “So I say I cannot understand this electorate.”
But Mr. Trump’s win here was not without precedent: 20 years ago, Patrick J. Buchanan, another insurgent who had never held elected office and who also ran as a populist, won the primary here, thwarting the party’s power brokers, thanks partly to blue-collar voters.
New Hampshire has proved a stabilizing force in the last two Republican primaries, catapulting John McCain and Mitt Romney toward the nomination. But with a primary in which independent voters can participate and voters can register on site at their regular polling place, Mr. Trump found a far more receptive state than Iowa, where the caucuses are restricted to Republicans and voters must sit through an extended session in the evening.
Mr. Trump’s advisers were optimistic about his prospects in the next state, South Carolina, where there is no party registration — meaning any registered voter can participate in the Republican contest — and where over half of the party’s primary electorate in 2012 did not have a college degree. But Mr. Trump will encounter some of the same challenges in the South that he did in Iowa, where voters were uneasy about his coarse language and lack of religiosity.