Ted Cruz
A triumphant Ted Cruz gives his wife, Heidi, a kiss as they celebrate his victory over Donald Trump in the Iowa caucuses.Reuters

Ted Cruz pulled off a surprise upset in the Iowa caucuses against GOP frontrunner Donald Trump, while Hillary Clinton narrowly beat Bernie Sanders in the closest Democratic race in the state's history.

Cruz made good on his promise that his crack organisation and hard work would beat Trump's media might. With 99% of the votes counted, he was a comfortable 5,100 votes ahead of the mogul. Senator Marco Rubio was a close third.

Cruz spent months touring the state and reaching out to important evangelical voters in the area. The win makes him a formidable contender in the delegate-rich, Southern state primaries in the coming weeks.

"God bless the great state of Iowa," Cruz crowed to supporters at his campaign's Iowa headquarters, his wife, Heidi, at his side. "Tonight is a victory for the grass roots. Tonight is a victory for courageous conservatives across Iowa and all across this great nation. Iowa has sent notice that the Republican nominee and the next president of the United States will not be chosen by the media, will not be chosen by the Washington establishment and will not be chosen by the lobbyists."

Trump spoke to his supporters for just three minutes, leaving them mostly deflated, and headed to New Hampshire for another frantic round of campaigning there for the next primary, reported CNN. "We will go on to get the Republican nomination and we will go on to easily beat Hillary or Bernie," Trump told supporters. "We finished second, and I have to say I am just honoured."

Cruz capped the night with 27.7% of the vote to Trump's 24.3% and Rubio's 23.1%. It's still a three-horse race though, which was especially good news to Rubio.

"They told me that I needed to wait my turn, that I needed to wait in line," a pleased Rubio told his backers. "But tonight here in Iowa, the people of this great state have sent a very clear message — after seven years of Barack Obama, we are not waiting any longer to take our country back."

US election 2016: Guide to the Republican candidatesIBTimes UK

It was only several hours later that Clinton was able to claim victory on the Democratic side, as the ledger remained at length too close to call. With 99.9% of precincts reporting, the former Secretary of State, won 49.9% of delegates against Sanders' 49.5%.

Hillary Clinton has won the Iowa Caucus," the Clinton campaign said. "After thorough reporting – and analysis – of results, there is no uncertainty and Secretary Clinton has clearly won the most national and state delegates. Statistically there is no outstanding information that could change the results and no way that Senator Sanders can overcome Secretary's Clinton's advantage."

However the left-wing senator has not conceded yet in what proved to be the closest race in the Iowa Democratic Caucus history, and did not rule out challenging the result, which he nevertheless celebrated saying the razor-thin contest gave his campaign a "kick-start". "This is a campaign that we can win," he told reporters aboard a flight to New Hampshire.

Earlier, Clinton also welcomed a close fight. "It is rare that we have the opportunity we have now to have a real contest of ideas, to really think hard about what the Democratic Party stands for," she said at her campaign headquarters with husband, Bill, and daughter, Chelsea, at her side.

"I am excited about really getting into the debate with Senator Sanders about the best way forward to fight for us and America."

Sanders seemed to smell victory as his supporters chanted "Feel the Bern!" Given the "enormous crisis facing our country, it is just too late for establishment politics and establishment economics," he said.

"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," he said. "And tonight, while the results are still not known, it looks like we are in a virtual tie."

The weakest candidates began to peel off. Former Maryland governor Martin O'Malley, the only other major Democratic candidate, suspended his campaign in the face of negligible support, as did former Arkansas governor Mike Huckabee in the GOP race. Republican candidate Ben Carson headed home to Florida, he said, to see his family and grab some "fresh clothes".

US election 2016: Guide to the Democrat candidatesIBTimes UK