Media playback is unsupported on your device Media caption Watch key moments from the Iowa speeches

Texas Senator Ted Cruz has won the Iowa Republican caucuses, in the first vote of the US presidential campaign.

"Tonight is a victory for courageous conservatives," he declared, to great applause, as he railed against Washington, lobbyists and the media.

He took 26% of the Republican vote, beating his rival, the frontrunner Donald Trump, and Marco Rubio.

Votes in the Democratic race are still being counted, with Hillary Clinton's camp saying they have narrowly won.

The aim of the primary and caucus races in the coming months is to determine which candidates will stand for the two main parties in the November presidential election.

Iowa caucus results

Republican vote, 99% reported:

Ted Cruz: 26%, eight delegates

Donald Trump: 23%, seven delegates

Marco Rubio: 23%, seven delegates

Ben Carson: 10%, three delegates

Rand Paul, Jeb Bush: one delegate each.

Chris Christie, Carly Fiorina, Jim Gilmore, Mike Huckabee, John Kasich and Rick Santorum: no delegates

Democratic vote, 99% reported:

Hillary Clinton: 50%, 22 delegates

Bernie Sanders: 47%, 21 delegates

Martin O'Malley: 0%, no delegates

source: The Associated Press

US election: Iowa results map

Mrs Clinton's campaign director in Iowa, Matt Paul, said there was "no uncertainty" that the former secretary of state and first lady had beaten Bernie Sanders, a left-wing senator from Vermont.

In six precincts the vote was decided by the toss of a coin - all going to Mrs Clinton, according to the Des Moines Register.

Iowa's Democratic Party said with one precinct still to be called, their results were "the closest in Iowa Democratic caucus history".

Mr Sanders said it was a "virtual tie". Before leaving for New Hampshire, which is holding party primaries on Tuesday, Mrs Clinton told her supporters she was "breathing a sigh of relief".

Media playback is unsupported on your device Media caption Hillary Clinton and Bernie Sanders are locked in a virtual tie at Iowa caucus

Image copyright Reuters Image caption Ted Cruz spent months criss-crossing the state to woo its influential voters

There was no such ambiguity from Republican victor Mr Cruz, the 45-year-old conservative who is disliked by the Republican Party leadership.

"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," he said.

Analysis: Anthony Zurcher, BBC News, Iowa

In the end it was a victory for organisation over enthusiasm. Despite trailing Donald Trump in the polls for much of the last two weeks, Ted Cruz swept to a comfortable win in Iowa.

During his victory speech, he repeatedly thanked his grass-roots support - and for good reason. He and his campaign had invested considerable time and money to grind out a victory in this key state, and they were ultimately rewarded for their efforts.

With this result Mr Cruz now has the momentum to survive what looks to be an uphill battle among the more moderate voters in New Hampshire, and then win over the deeply conservative, evangelical voters of Southern states that dominate the primary calendar in the following weeks.

It appears increasingly likely that a showdown for Mr Cruz looms on the horizon with the surprise third-place finisher in Iowa, Senator Marco Rubio. And Mr Trump - even if his supporters did not turn out in the numbers expected - will surely remain a factor.

Winners and losers after Iowa vote

Mr Trump congratulated the Texas senator and said he was "honoured" by the second-place finish.

Mr Rubio, who has struggled to gain support in recent months, has performed far better than expected, and finished just one percentage point behind Mr Trump.

Media playback is unsupported on your device Media caption Supporters of the US presidential candidates give their take on their favourite

Image copyright CBS Image caption Marco Rubio gave a speech that was like a victory rally

Image copyright Getty Images Image caption Bernie Sanders said the Iowa vote had "astounded the world"

Meanwhile, two candidates are bowing out.

Sources close to Democrat Martin O'Malley, former Maryland governor, have told the BBC that he will suspend his campaign - narrowing the field to two competitive candidates.

On the Republican side, Former Arkansas Governor Mike Huckabee tweeted that he too would suspend his campaign.

US editorials on Iowa vote:

The Des Moines Register's editorial says "Cruz won Iowa the old-fashioned way"

"Cruz's strategy, which included at least one visit to each of Iowa's 99 counties, paid off. He slogged his way across Iowa by car and by bus, stopping in small-town cafes and gymnasiums, while his biggest threat, Donald Trump, travelled by personal jet and by helicopter to large-scale rallies.

The Washington Post says Marco Rubio and Bernie Sanders were the real winners in Iowa

"In the short term, Donald Trump was the biggest loser - true of any front-runner but even truer of a candidate whose campaign raison d'etre is that he is a winner."

The New York Times says "Mr Sanders is all about heart"

"His highly enthusiastic crowd cheered his promises to "break up the banks", regardless of whether that is remotely possible."

USA Today said Iowa caucus voters had rewritten the script

"If the past eight months have taught anything, it is that the political landscape can change dramatically, defying all predictions. This race is just beginning, and candidates who live by the polls can die by them as well."

New Hampshire Union Leader says: "Thank you, Iowa: We'll take it from here"

"Most candidates this year spent more time listening than talking. This makes for better candidates, and better presidents."

Iowa has an unusual election system based on caucuses, which involve people gathering at private homes, schools and other public buildings across the state.

Democratic voters divide themselves into groups based on their preferred candidate, but the Republican caucus process is more like a traditional ballot.

More on Senator Ted Cruz

What would a Cruz presidency be like? Imagining the first terms of Mr Cruz and other candidates

Three things Ted Cruz says: A 60-second summary of the Republican candidate's stump speech

The Texan Tea Partier: Ted Cruz's rapid, rocky ascension to presidential candidate

How does a US election work? If you want to be president, it helps to be governor, senator, or five-star military general - and have lots of patience