The purpose of an election in a democracy is to elect leaders according to the "will of the people". The definition of "the people" is limited; only adults who aren't felons who registered to vote in time for the election and who actually bother to show up and vote are considered. So it's a bit limited to start with, and that's ignoring further constraints like election rules, the electoral college, primaries, etc.
Those who vote provide a measurement of the "will of the people". Like all real-world measurements, it's not perfect. People accidentally mark the wrong candidate, chads are left hanging, ballots jam in machines that read them, ballot boxes get lost, and there's general election fraud (by Democrats and Republicans alike). I've seen error rate estimates by credible sources of one to five percent with the median being around two percent.
How many times have you heard someone state that Al Gore won the popular vote in 2000 and therefore it was certainly the "will of the people" that Gore be president? I've heard it lots of times. But with a two percent error rate, the likelihood that the popular vote count as measured meant that the majority of voters actually intended for Gore to be President is only about 85%. In other words, there still about one in six chance that the "will of the people", according to the popular vote, was for Bush to be President.
Of course, the popular vote doesn't matter in our current election system. I only mention it as an example of how there is never certainty in an election process, and in a close election there is a lot of uncertainty. Once you look at Florida and other close states in the 2000 election, the only thing that's certain is that nobody can realistically be anywhere near certain what the "will of the people" was in the 2000 election.
Since it's clear that the "will of the people" can't really be known with much confidence in a close election, and that fraud (from both sides) may have overwhelmed the accuracy of the election measurements (counts), what's the best way to resolve the outcome of the election? Clearly the best way is for one side to concede the election to the other. That didn't happen last time. Neither Gore nor Bush had the grace to do so.
The only other ways to resolve the election are the courts and violence. Assuming the upcoming election is as close as I currently expect it to be, I wouldn't be surprised to see quite a lot of both.
Update: Here is a good article on vote fraud and contested elections.