A tight contest in the Democratic Iowa caucuses came down to the wire Monday night, and some of the electoral affair was decided by pure luck.

The first major event on the road to the 2016 United States presidential election saw Democratic front runners Hillary Clinton and Vermont Sen. Bernie Sanders practically tied by the end of the process.

Even after the Iowa Democratic Party declared that all 1,683 precincts had reported in, a margin of only 0.2 percent separated the candidates; 49.8 percent Democratic delegate equivalents went to Secretary Clinton while Senator Sanders came away with 49.6 percent. Former Maryland Gov. Martin O’Malley ended his campaign Monday after winning only 0.5 percent of the delegates.

The close caucus race between Clinton and Sanders wasn't just about candidate campaigning and voter deliberation. The Des Moines Register reported Tuesday that several Iowan precincts awarded their delegates on the basis of a coin toss.

Here's what happened: In several caucus precincts, the number of attendees exceeded the number of votes in the final preference count. This led to a discrepancy between the voter support for each candidate and the number of delegates each precinct could select. These “orphan delegates” had to be assigned somewhere, so precinct leaders contacted Democratic leaders through a caucus hotline. The party officials told caucus-goers to grant the candidates the final delegate by flipping a coin.

The Register found that in total, six precincts ended up with a tie or some problem that led to decision by chance. In every case, Clinton’s side won by calling the correct side of a coin.

The county convention delegates assigned in the caucus are not the same as the delegate equivalents used to determine the percentages in the final results. The more than 11,000 representatives are instead elected to one of Iowa’s 99 county conventions that later decide the delegates to send to congressional district, state, and eventually national conventions.

While the few delegates decided by coin toss Monday night had a minimal impact on the overall results, the razor-thin gap between first and second place meant every head counted for both Democratic candidates. Clinton’s campaign finally declared victory Tuesday after all precincts reported in, citing the official results as evidence of a win.

“After thorough reporting — and analysis — of results, there is no uncertainty, and Secretary Clinton has clearly won the most national and state delegates,” said Matt Paul, Clinton’s Iowa campaign manager, in a written statement. “Statistically, there is no outstanding information that could change the results and no way that Sen. Sanders can overcome Secretary Clinton's advantage.”

The Iowa Democratic Party announced early Tuesday morning that Clinton had scraped by with 699.57 delegate equivalents to Sanders’ 695.49, per the Register.

Sanders said the caucus ended in a "virtual tie" late Monday night, with one of his advisers saying their campaign took on Clinton's and "fought them to a draw," reported the Associated Press.

The state's Republican caucus results favored Sen. Ted Cruz, who won a 27.6 percent share of votes cast within his party. Donald Trump earned 24.3 percent of the Republican votes, and Sen. Marco Rubio garnered 23.1 percent. No other Republican candidate won more than 10 percent of party votes in the caucuses.