DES MOINES, Iowa (AP) — Texas Sen. Ted Cruz, a fiery conservative loathed by his own party's leaders, swept to victory in Iowa's Republican caucuses Monday, overcoming billionaire Donald Trump and a stronger-than-expected showing by Florida Sen. Marco Rubio. Among Democrats, Bernie Sanders rode a wave of voter enthusiasm to a virtual tie with Hillary Clinton, long considered her party's front-runner.
Cruz's victory over Trump was a testament to his massive get-out-the-vote operation in Iowa and the months he spent wooing the state's influential conservative and evangelical leaders.
"Iowa has sent notice that the Republican nominee and next president of the United States will not be chosen by the media, will not be chosen by the Washington establishment," Cruz said.
His comments were echoed by Sanders, underscoring the degree to which voter frustration with the political system has crossed party lines in the 2016 campaign.
"It is too late for establishment politics and establishment economics," said Sanders, who declared the Democratic race a "virtual tie."
Clinton took the stage at her own campaign rally saying she was "breathing a big sigh of relief" but with the Democratic race too close to call. Aware that even a slim victory over Sanders would reinvigorate questions about her candidacy, she foresaw a long race to come.
"It is rare that we have the opportunity we do now, to have a real contest of ideas, to really think hard about what the Democratic Party stands for and what we want the future of our country to look like," Clinton said.
Trump has shaken the Republican Party perhaps more than any other candidate, though he was unable to turn his legion of fans into an Iowa victory.
He sounded humble in defeat, saying he was "honored" by the support of Iowans. And he vowed to keep up his fight for the Republican nomination.
"We will go on to easily beat Hillary or Bernie or whoever the hell they throw up," Trump told cheering supporters.
For Clinton's supporters, the tight race with Sanders was sure to bring back painful memories of her loss to Barack Obama in 2008. Her campaign spent nearly a year building a get-out-the-vote operation in Iowa yet still seemed to be caught off guard by the enthusiasm surrounding Sanders.
A self-declared democratic socialist from Vermont, Sanders drew large, youthful crowds across the state with his calls for breaking up big Wall Street banks and his fierce opposition to a campaign finance system that he says is rigged for the wealthy.
With the race too close to call, Sanders' aides said they had been told by the Iowa Democratic Party that it did not have results from several precincts and had asked the campaigns to help get the missing information. The party said it was awaiting results from a "small number of outstanding precincts" and had reached out to the campaigns for help contacting the chairs from those sites.
Cruz modeled his campaign after past Iowa Republican winners, visiting all of the state's 99 counties and courting evangelical and conservative leaders. While candidates with that portfolio have often faded later in the primary season, Cruz hopes to ride his momentum to the nomination.
Trump took second place, but Rubio, favored by more mainstream Republicans, gave him a battle even for that.
"We have taken the first step, but an important step, to winning the nomination," Rubio said at a campaign rally in Des Moines.
Candidates in both parties faced an electorate deeply frustrated with Washington. While the economy has improved under President Barack Obama, the recovery has eluded many Americans. New terror threats at home and abroad have increased national security concerns.
Voters at Republican caucuses indicated they were deeply unhappy with the way the federal government is working. Half said they were dissatisfied and 4 in 10 said they were angry, according to surveys conducted by Edison Research for The Associated Press and the television networks.
Six in 10 Democratic caucus-goers wanted a candidate who would continue Obama's policies. Young voters overwhelmingly backed Sanders.
Both parties were drawing new voters. About 4 in 10 participants in each party said they were caucusing for the first time.
In Iowa, which has for decades launched the presidential nominating contest, candidates also faced an electorate that's whiter, more rural and more evangelical than many states. But, given its prime leadoff spot in the primary season, the state gets extra attention from presidential campaigns.
The caucuses marked the end of at least two candidates' White House hopes. Former Maryland Gov. Martin O'Malley ended his longshot bid for the Democratic nomination. Former Arkansas Gov. Mike Huckabee dropped out on the Republican side.
Republicans John Kasich, Chris Christie and Jeb Bush were all spending Monday night in New Hampshire — not only to get a jump on the snow moving into Iowa but also to get ahead of their competitors in a state with voters who are expected to be friendlier to more traditional GOP candidates.
While both parties caucused on the same night in Iowa, they did so with different rules.
Republicans voted by private ballot. The state's 30 Republican delegates are awarded proportionally based on the vote, with at least eight delegates going to Cruz, seven to Trump and six to Rubio.
Democrats form groups at caucus sites, publicly declaring their support for a candidate. The final numbers are awarded proportionately, based on statewide and congressional district voting, determining Iowa's 44 delegates to the national convention.
Even without a declared winner, The Associated Press awarded all but one of those delegates. Clinton led Sanders 22 to 21, with the remaining delegate to be awarded to the statewide winner.
Pace reported from Washington. Associated Press writers Lisa Lerer, Ken Thomas, Scott McFetridge and Scott Bauer contributed to this report.
Follow Julie Pace and Catherine Lucey on Twitter at: http://twitter.com/jpaceDC and http://twitter.com/catherine_lucey