And the winner is …

Following days of chaos and uncertainty, Pete Buttigieg on Thursday night appeared to be the winner of the Iowa caucus.

The former mayor of South Bend, Indiana, narrowly defeated Vermont Sen. Bernie Sanders as the last of the precincts reported their tallies, the Iowa Democratic Party said.

He had 564 state delegate equivalents to Sanders’ 562, or a 26.2% advantage over Sanders’ 26.1%.

Buttigieg, 38, had already declared himself the winner of the crucial caucuses the night they were held, before any of the official results were tallied.

Caucus night on Monday descended into chaos into Tuesday morning, as “inconsistencies” in reporting ended with zero results being announced.

On Thursday morning, reporting from 97% of precincts showed the two presidential hopefuls in a near tie, and Sanders declared himself the winner as well.

Tom Perez, the chairman of the Democratic National Committee, called for a “recanvass” of the results, saying it was needed to “assure public confidence.”

However, Iowa chairman Troy Price suggested in a statement that he would only pursue a recanvass if a campaign requested one.

Candidates have until 1 p.m. on Friday to request a recanvass.

A review by the NBC News Decision Desk on Thursday found that the caucus results of at least 77 of the state’s 1,711 precincts were rife with potential mistakes and inconsistencies.

“There are definitely some inaccuracies in the data,” said John Lapinski, director of the Elections Unit at NBC News, who leads the Decision Desk.

“When you have a tied result, even the smallest sort of inaccuracy could be consequential,” he said. “If there was a lot of spread in this race, these errors would be insignificant. But when we are talking about a tied race, everyone wants to know that every number is correct.”

Lapinski added, “In close races, every number is consequential.”

The Associated Press on Thursday evening said it was unable to declare a winner due to the tight margin and the irregularities in the process.