BOISE - Bernie Sanders won Idaho's Democratic caucuses Tuesday night. With long lines in Ada and Canyon counties, and big crowds at caucusing sites across the state, the numbers were slow to come in.

But when the announcement was finally made at 12:30 a.m., Sanders came out on top with 18,640 votes. Hillary Clinton was a distant second with 5,065 votes - a margin of 78 percent to 21 percent. In Ada County, Sanders got more than 80 percent of the vote.

At stake were Idaho's 27 delegates. Because both candidates got at least 15 percent of the vote statewide, the delegates will be split proportionally.

The start of caucusing in Ada and Canyon counties was delayed by more than an hour, after long lines formed outside the caucus sites. In Ada County, the line wrapped along several city blocks.

MORE: Long lines, big crowds at Idaho Democratic caucuses

At about 8 p.m., organizers began handing out caucus ballots to people waiting in line outside the Boise Centre.

One worker said, "You are participating in the largest caucus in the history of the United States."

Because most states host their caucuses by precincts, and not counties, that statement may well be true. More than 9,100 voters participated in Ada County's caucus.

RELATED: Sanders rallies supporters during Boise campaign stop

Also Tuesday night, Sanders won Utah's caucuses, while Clinton won Arizona's primary.

The Vermont senator says the support in Tuesday's races "give me confidence that we will continue to win major victories in the coming contests."

On the Republican side, Donald Trump won Arizona and Ted Cruz won Utah.