DENVER (AP) -- Donald Trump has notoriously refused to say he would accept a loss to Hillary Clinton in the Nov. 8 election, raising the prospect of a prolonged legal fight that could roil the nation. Legal battles over voting results are rarely successful but they do happen -- most famously in 2000, when a 537-vote margin separated Democrat Al Gore and Republican George W. Bush in the must-win state of Florida. In that case, it took a Supreme Court ruling along party lines to resolve the dispute and make Bush president.
Here's a look at how Trump -- or Clinton, should she be in a similar situation -- could try to challenge the election results.
IT'S GOTTA BE CLOSE
State governments formally certify the winners of presidential elections within their boundaries, and it's not hard to legally contest them.
"Anybody can file anything," said Richard Hasen, a law professor at the University of California-Irvine. "There's no high bar to filing a complaint."
Such a filing would only matter, he said, if the race is close.
In a presidential election, that means it would have to come down to a single battleground state that both candidates need to win to reach 270 electoral votes, and where the margin between them is about one percentage point or less. That's not impossible --- see the 2000 election --- but it is very rare. For example, in 2008 it took weeks of counting to determine who won Missouri, but there was no legal fight because Barack Obama had already won a commanding majority in the Electoral College.
Clinton has held a solid lead in the electoral map throughout the race, though Trump has been gaining in some key states during this final week.
"The question is, do you have a specific state where the margin is close and the outcome could change the outcome of the presidential election?" said Marc Braden, an election lawyer in Washington.
IT STARTS AFTER ELECTION DAY
On Tuesday and early Wednesday, the Associated Press and other news organizations will look at ballot returns and call a winner in a variety of battleground states and the presidential election --- unless there's a virtual tie. But that's not the official, certified election result. Local and state election officials will continue to count votes, sometimes for several days. The overall margins can shift. If the margins are tight enough --- thresholds vary from state to state but are often below 1 percentage point --- they can trigger an automatic recount.
A recount is an administrative procedure, but it can spawn litigation if parties object to the way it's being conducted. (That's what led the Supreme Court to get involved in 2000.) Recounts rarely change the outcome of an election unless the margin is already in the low triple-digits, Braden said.
GOING STRAIGHT TO COURT
People can also directly challenge in court a state's certification of an election. These are rarely successful but they do happen. The 2004 gubernatorial election in Washington state went through three recounts before Democrat Christine Gregoire was certified as the winner. A Republican challenge to that decision failed in state court. In 2008, a close Senate race in Minnesota went all the way to the state Supreme Court before Democrat Al Franken became the state's junior senator --- eight months after the election.
The candidate would have to be able to argue that some sort of systemic problem, error or fraud put the candidate at a disadvantage in the election or subsequent counting. Trump has made vague, sweeping allegations --- without evidence --- of massive voter fraud. But experts say it is relatively rare and usually inconsequential. Braden, a member of the Republican National Lawyers Association, said recounts can turn up small-scale voter fraud but almost exclusively in local races. The number of fraudulent ballots, he said, is normally only enough to shift a small contest.
"I don't see any reason to believe this election is different than prior ones," Braden said. "There is fraud but is it significant and widespread? No."
SLOW DOWN, HURRY UP
There are processes built into a presidential election that make it likely the race will drag into "overtime" if the results are close, says Ohio State University law professor Edward Foley, as well as limit how long that period can last.
There's no requirement for states to declare winners right away and most won't for days. States have to be careful sorting out challenged ballots or ones with potential errors --- again, the sort of administrative task that very rarely changes an election result but can delay it.
But Congress has set a Dec. 12 deadline for states to submit a ratified vote tally, Foley said. By Dec. 19, the states are required to have chosen electors who will meet that day --- another constitutional requirement. And by Jan. 6, Congress has to have received the electors' votes.
That would make it hard for a legal fight to go too far into December, said Foley, who's written a book on the history of challenged U.S. elections. Fights have gone down to the wire: In 1876, for example, Rutherford Hayes was declared the winner of the election only two days before Inauguration Day.
There are two people who can help ensure that doesn't happen this time: Republican congressional leaders Mitch McConnell in the Senate and Paul Ryan in the House. Their public acceptance of an election result could end a potential legal challenge, especially from a candidate like Trump, who is running on the Republican ticket.
"There are enough parts to our democratic system that I think we can handle one candidate being litigious, if everyone else says it's over," Foley said.