US Senator Ted Cruz has soundly defeated billionaire Donald Trump in Iowa's Republican nominating contest, upending the party's presidential race and creating a three-way competition with establishment candidate Senator Marco Rubio.
On the Democratic side, officials said former Secretary of State Hillary Clinton had won by a razor-thin margin against US Senator Bernie Sanders of Vermont, the closest in Iowa Democratic caucus history.
Cruz, a conservative from Texas, won the first state Republican contest in the 2016 race on Monday with 28 percent of the vote compared with 24 percent for businessman Trump. Rubio, a US senator from Florida, came in third with 23 percent, making a stronger-than-expected finish.
With Democrat Clinton prevailing by only four delegates, according to party figures, Sanders, a self-described democratic socialist, declared the result a "virtual tie".
"Hillary Clinton has won the Iowa caucus," Matt Paul, the Iowa state director for Clinton said in a statement released in the early hours of Tuesday morning.
Cruz's win and Rubio's strong showing could dent the momentum for Trump, whose candidacy has alarmed the Republican establishment and been marked by controversies ranging from his calls to ban Muslims temporarily from entering the US to promising to build a wall on the US-Mexican border.
"Tonight is a victory for courageous conservatives across Iowa and all across this great nation," Cruz, 45, said during a victory speech lasting more than 30 minutes.
An uncharacteristically humbled Trump, 69, congratulated Cruz and said he still expected to win the Republican nomination. Opinion polls show Trump leading nationally and in New Hampshire, which holds the next nominating contest.
Unusually large crowds poured into schools, churches and other venues for the caucuses, in which voters gather together to select a candidate.
Cruz's well established get-out-the-vote effort helped overcome the enthusiasm from large crowds that have shown up for Trump's rallies. Trump skipped the last Republican debate before the caucus because of a dispute with host FOX News. A Trump adviser said his second-place finish was expected.
Rubio, 44, may benefit from that momentum as much as Cruz.
The Florida legislator established himself as the mainstream alternative to the two front-running rivals.
"Rubio has staying power. He weathered US$30 million in negative ads and late deciders broke his way due to his upbeat and optimistic close," said Republican strategist Scott Reed.
Cruz was buoyed by evangelical support and thanked God for his win.
The results of the Democratic race put pressure on Clinton to siphon support away from Sanders, who has won over politically left-leaning voters with his promises to take on Wall Street and start fresh with healthcare reform.
Clinton, 68, said she was breathing a "big sigh of relief" after the results. She lost Iowa to then-senator Barack Obama in the 2008 Democratic race and never recovered.
Sanders, 74, declared himself overwhelmed. The lawmaker, who smiled broadly as he addressed supporters, is leading in New Hampshire, home to next week's second contest, but trails Clinton in other states such as South Carolina, which holds the third contest.
"Nine months ago, we came to this beautiful state, we had no political organisation, we had no money, we had no name recognition, and we were taking on the most powerful political organisation in the United States of America," Sanders said.
Former Maryland governor Martin O'Malley, who had trouble gaining any traction in the Democratic race, suspended his campaign after coming in third in Iowa with 0.6 percent.
Republican establishment candidates more traditional than Rubio did not fare well in Iowa. Former Florida governor Jeb Bush took 2.8 percent, Ohio Governor John Kasich took 1.9 percent, and New Jersey Governor Chris Christie took 1.8 percent.
Surgeon Ben Carson, an outsider, placed fourth among Republicans with 9 percent while former Arkansas governor Mike Huckabee said he was suspending his campaign for the party's nomination. Huckabee won the Iowa caucus in 2008.