Wisconsin presidential primary voters shunned front-runners from both the Democratic and Republican parties on April 5. Here are key moments from the victory speeches of Sen. Ted Cruz (R-Tex.) and Sen. Bernie Sanders (I-Vt.). (Sarah Parnass/The Washington Post)

Sen. Ted Cruz has won the Republican primary in Wisconsin, and Sen. Bernie Sanders has won the Democratic primary, according to exit polls and early returns.

The Associated Press called the race for both men within an hour of polls closing at 9 p.m. Eastern time. In both races, the result meant a defeat for the party’s national front-runner — although the loss may be more damaging to Republican Donald Trump, because he is in greater danger of failing to lock up the party’s nomination ahead of this summer’s convention.

In the Republican race, the first results showed a massive lead for Cruz: With more than 20 percent of votes in, he led Trump by more than 20 percentage points. Trump may still get some delegates from Wisconsin, however: The state awards some delegates by congressional districts, and Trump was leading in rural districts in Wisconsin’s northwest.

Cruz savored the victory, casting it as proof that the GOP race had turned. The party’s anti-Trump forces had coalesced behind an unlikely champion: a Texas senator who seemed like the worst possible choice for the GOP establishment, right up until they met candidate Trump.

“Tonight is a turning point. It is a rallying cry,” Cruz told supporters in Milwaukee. “We have a choice. A real choice. The national political terrain began to change two weeks ago,” he said, meaning when he won by a large margin in Utah. Cruz said his campaign had raised $2 million on Tuesday alone.

How Ted Cruz won the Wisconsin GOP primary, in 60 seconds (Peter Stevenson/The Washington Post)

In exit polls, Cruz seemed to be winning in most slices of the GOP electorate. He won Republicans with college degrees, leading Trump by nearly 20 points. And Cruz also narrowly led Trump among Republicans without college degrees, a group that has been strongly pro-Trump in other states. Exit polls reported by CNN showed Cruz winning with both men and women, with born-again Christians and with everybody else, and in all age groups (except for Republicans under 30, of whom there were too few to poll).

Trump was said to be watching the returns with family in New York on Tuesday night. He held no election-night rally, nor even a news conference at one of his golf courses.

Trump’s campaign issued a statement that called Cruz “Lyin’ Ted,” and said his victory came because the party’s establishment and conservative talk-radio hosts had been behind him. Oddly, on a night when Cruz had defeated Trump widely in the polls, Trump accused Cruz of trying to “steal” the nomination from him.

“Ted Cruz is worse than a puppet — he is a Trojan horse, being used by the party bosses attempting to steal the nomination from Mr. Trump,” Trump’s statement said. It went on to predict victory for Trump in New York.

Ohio Gov. John Kasich, the third candidate in the GOP race, was running far behind Trump at about 15 percent in Wisconsin.

Sanders addressed cheering supporters in Laramie, Wyo., where Democrats will hold their caucuses Saturday. He said his campaign was gaining momentum, and paraphrased Abraham Lincoln’s Gettysburg address: “This is a campaign of the people, by the people, and for the people.

“Real change never, ever takes place from the top on down. It always takes place from the bottom on up,” Sanders added.

Sanders had been leading Clinton by about seven percentage points, 53 percent to 46 percent, with 30 percent of precincts reporting

A victory on that scale may not allow him to make up significant ground on Clinton in the race for Democratic convention delegates. But it will allow him to cite growing momentum going into a crucial contest in New York — where Sanders was born, and where Clinton served as senator — on April 19. A win in Wisconsin also allows Sanders to make the case to “super-delegates,” who can make up their minds about whom to support.

Exit polls showed that Sanders was doing far, far better than Clinton among younger voters: Polls reported by CNN showed that Sanders won voters under age 30 by over 60 percentage points, larger than his average margin of about 40 points in contests this year. Sanders also led Clinton by a 2 to 1 margin among those aged 30 to 44. Clinton led by a modest 9 percentage points among voters ages 45-64, and by a wider 22-point margin among seniors, but it was unclear whether this would be enough to overcome Sanders’s edge with younger voters

There was also good news for Democrats generally. More than 7 in 10 Democrats said they are “excited” or at least “optimistic” about Clinton and Sanders alike. No Republican candidate got such widespread positive reviews: The best was for Cruz, about whom 6 in 10 Wisconsin voters said they were excited or optimistic.

Barely 4 in 10 were excited about Trump.

Cruz gained significant support here in the past few days thanks to an endorsement by Wisconsin Gov. Scott Walker and influential Wisconsin talk-radio hosts. He also owes some thanks to Trump, who has spent the time since the last GOP primaries inflicting a series of disasters on his own campaign.

Trump re-tweeted a fan who was insulting Cruz’s wife. Trump called for some kind of “punishment” against women who have abortions. And Trump defended his campaign manager, who’d been charged with battery for grabbing a reporter, by suggesting that the reporter’s pen could have been “a little bomb.”

A new Reuters-Ipsos poll Tuesday showed that Cruz was in a dead heat with Trump nationally after having trailed him by nearly 20 points a month ago.

In exit polls from Wisconsin, nearly 4 in 10 Republicans said they were scared about what Trump would do as president, while only about 1 in 10 say that about either Cruz or Kasich, according to exit polls reported by The Associated Press.

A Cruz win in Wisconsin makes it much harder for Trump to win the nomination without a fight at the convention. And if it comes down to a fight at the convention, Cruz has out-hustled Trump to secure support among individual delegates.

In early exit polling, only about one-third of Republican voters in Wisconsin said Trump had the best chance to beat Clinton in a general election, according to polls reported by ABC News. Cruz did better: More than 4 in 10 named Cruz as the Republican with the best chance. And fewer than 2 in 10 choose Ohio Gov. John Kasich, the more moderate candidate running a distant third.

And exit polling reported by CNN found a striking note: Among the 68 percent of voters who supported a temporary ban on Muslims entering the United States, Ted Cruz carried 50 percent to Trump’s 42 percent. Trump had won this group in every contest where exit polls asked the question, except in Texas, Cruz’s home state, where he also lost Muslim ban supporters by an 8-point margin.

In an interview Tuesday with MSNBC’s Chris Jansing outside a Waukesha, Wis., polling site, Trump admitted that he made missteps even as he refused to concede that polls showing him trailing Cruz were accurate.

“But I’ve had worse weeks on the campaign. I mean, I’ve had so many weeks that — I think a couple that were worse. And in one case I went up in the polls,” he said. “So, you know, it couldn’t have been so disastrous.”

Trump has also dismissed speculation about a possible break in his momentum by pointing to his strengths in New York — his home state, which holds its primary April 19 — and in the string of Eastern states that vote later this month.

Anti-Trump Republicans, who have poured millions of dollars into attack ads around the country, are hopeful that a loss in Wisconsin will signal a break in the momentum that has kept Trump steadily rising in the polls.

A loss in Wisconsin, they believe, would increase the likelihood of a contested Republican convention in July — a strategy that rests on keeping Trump from crossing the requisite 1,237-delegate threshold he needs to clinch the nomination outright.

Speaking on “Fox & Friends” Tuesday, former New York mayor Rudolph W. Giuliani — who has not made an endorsement in the race — said support for Cruz by Wisconsin Gov. Scott Walker (R) has given the Texas senator a critical boost.

“Walker may have one of the better operations in the country, because of the way it’s been tested,” Giuliani said, referring to the 2012 recall challenge and other elections the governor has survived. “Absent the Walker machine, Trump wins Wisconsin.”

In a private document circulated over the weekend and obtained by The Washington Post, Trump campaign senior adviser Barry Bennett revealed the mounting frustrations among the billionaire’s top aides as they closed what had been a tumultuous week.

Titled “Digging through the Bull S---,” Bennett’s memo urged Trump campaign manager Corey Lewandowski — who was charged with battery last week after allegedly yanking a reporter — and others to ignore critics who have questioned whether Trump’s campaign has waned.

“America is sick of them. Their idiotic attacks just remind voters why they hate the Washington Establishment,” Bennett wrote, citing tracking poll data favorable to Trump.

“Donald Trump 1,” Bennett declared, as if he was scoring the past week. “Washington Establishment/Media 0.”

That sort of sentiment resonated with Lisa Oleniczak, who voted for Trump at a precinct in Oak Creek, just south of Milwaukee.

“He’s not from the establishment,” she said.

But Ron Kurtz, 67, said he voted for Cruz because the New York billionaire’s attacks on Sen. John McCain (R-Ariz.) and other elected GOP officials had gone too far.

“I don’t like some of Trump’s statements — like cutting down McCain for being captured,” he said.

In the run-up to Tuesday, Clinton campaigned fewer days and before smaller crowds in Wisconsin than Sanders. She had already turned much of her attention ahead to the larger stakes in New York, on April 19. She did not mention the Wisconsin race during a rally Monday in Manhattan to cheer the state’s approval of a $15 minimum wage.

After holding a rally Monday night in Milwaukee, Sanders mingled with voters and stayed for breakfast Tuesday morning at Blue’s Egg diner, a city institution.

“If people come out to vote in large numbers, I think we’re going to do very, very well,” Sanders told reporters as he entered the restaurant with Barbara Lawton, a former Wisconsin lieutenant governor, before ordering blueberry pancakes.

Dale Dulberger, 66, of nearby Wauwatosa, Wis., said he heard on the news that Sanders was at the diner and wanted to come say hello after having voted for him Tuesday morning.

“I think he’s really authentic,” Dulberger, who teaches at a county technical college, said of Sanders. “I think people believe what he’s saying. His proposals are idealistic, but that’s what a president is supposed to do.”

Donna Ernst, who sells insurance and lives in nearby New Berlin, waited outside the diner to see Sanders, and said voting for him was an easy decision.

“He has a heart,” said Ernst, 43. “He’s not corrupt. He’s not greedy.”

Sanders planned to travel later Tuesday to campaign in Wyoming, which holds its Democratic caucuses Saturday.

Aides to Clinton, who is spending the day in New York City, have been telegraphing a potential loss in Wisconsin for months. She is scheduled to appear on ABC’s morning program “The View” and hold a Women for Hillary town hall-style event in Brooklyn in the afternoon.

Speaking on “The View,” Clinton tackled a range of issues, including the perception that she’s inauthentic (“I’ve been pretty much the same person” throughout her career, she said) and how she communicates with her granddaughter Charlotte on her Apple devices (“FaceTime was invented for grandparents.”)

But she reserved her sharpest comments for Trump rather than Sanders.

“I just don’t understand what he thinks is the role of somebody running for president,” Clinton said Tuesday. “I don’t think it is to scapegoat people, divide people or engage in this kind of prejudice and paranoia.”

Clinton’s campaign announced no plans for an election-night party, instead scheduling an evening fundraising party in New York.

Sanders has made political hay with Clinton’s fundraising schedule, frequently noting that his donations are almost all raised online, in small amounts, while she relies heavily on big checks from wealthy donors.

The third Republican still in the race, Ohio Gov. John Kasich, is far behind his two rivals in recent Wisconsin polls. He spent Monday campaigning in New York in advance of that state’s primary in two weeks.

Forty-two delegates are at stake for Republicans, while 86 delegates will be awarded based on the Democratic vote (Wisconsin also has 10 Democratic “super-delegates,” who can make up their own minds and aren’t bound by the results of the vote). Since delegates are assigned proportionally on the Democratic side, Sanders will have a difficult time slicing into Clinton’s overall lead if he does not win by an overwhelming margin.

Wagner reported from Milwaukee, Fahrenthold and Eilperin from Washington. Jose A. Delreal and Sean Sullivan in Milwaukee, and Robert Costa, Scott Clement, Jenna Johnson and Abby Phillip in Washington contributed to this report.