President Barack Obama has said Republican Donald Trump's insistence that he might not accept the election result is "dangerous".

Speaking at a campaign rally in Miami for Democratic nominee Hillary Clinton, the president said Mr Trump's comments undermined American democracy.

Mr Trump refused in a televised debate to say he would accept the outcome of the election on 8 November.

He later said he would accept a "clear" result but left a challenge open.

Speaking in Ohio on Thursday, Mr Trump said, with a grin: "I would like to promise and pledge to all of my voters and supporters and to all of the people of the United States, that I will totally accept the results of this great and historic presidential election - if I win."

In the same speech, he said he would accept a clear election result but reserved the right to file a legal challenge in the case of a questionable one.

During Wednesday night's debate with Mrs Clinton, when moderator Chris Wallace asked Mr Trump if he would accept losing to her, the Republican nominee said he would "keep you in suspense".

Mr Trump's campaign manager, Kellyanne Conway, later insisted that the candidate had meant he would not concede until the "results are actually known".

Republican Senator John McCain, who lost to Mr Obama eight years ago, said: "A concession isn't just an exercise in graciousness. It is an act of respect for the will of the American people, a respect that is every American leader's first responsibility."

First Lady Michelle Obama also joined the attack on Thursday, saying "you do not keep American democracy in suspense".

With the Clinton camp - Kim Ghattas, BBC News

Hillary Clinton walked on to her campaign plane to the cheering and clapping of her aides.

She told reporters she was relieved and grateful and joked there would be "no more naps"- a reference to Trump's repeated description of her prep days off the campaign trail as naps.

Mrs Clinton's stand-in for Mr Trump during the mock debates was one of her close aides, Philippe Reines, who took the role so seriously that he wore Trump cufflinks, shoe lifts and the same red tie as Mr Trump. After the debate, Mrs Clinton and Mr Reines embraced and he called her a "badass hombre".

Clinton aides said she would continue to highlight Mr Trump's refusal to pledge he would accept the results of the election. But would it be a real crisis on election day? Not if the result was a decisive win, they seemed to quietly indicate.

If Mrs Clinton and her team felt that she had closed the deal on stage, they kept their confidence in check. But the mood on the plane was certainly relaxed.

What happens next?

The two candidates will spend the remaining 18 days before the election criss-crossing the US in their bid to persuade undecided voters. Expect to see lots of appearances in battleground states such as Ohio, North Carolina, Florida and Pennsylvania.

Voters will go to the polls on Tuesday 8 November to decide who becomes the 45th President of the United States