US President Donald Trump has fired top cybersecurity official Chris Krebs in a message on Twitter.

Mr Trump accused him, without evidence, of making a "highly inaccurate" statement affirming the 3 November election was secure and rejecting claims of fraud.

The president has made debunked allegations that the election was "rigged" and has refused to concede defeat to President-elect Joe Biden.

His campaign has filed a flurry of lawsuits in battleground states, although election officials in both parties have said they see no evidence of serious irregularities.

Mr Krebs' work in protecting the election from hackers and combatting disinformation about the vote won praise from politicians of both parties, as well as state and election officials around the country.

But he drew the ire of Mr Trump and his allies, who were annoyed over his refusal to support allegations of election meddling.

He had told associates last week that he expected to be fired.

Mr Trump said on Twitter that Mr Krebs had assured people in a "highly inaccurate" statement that the election had been secure when there were "massive improprieties and fraud – including dead people voting, Poll Watchers not allowed into polling locations," and voting machine errors that flipped votes from Mr Trump to Mr Biden.

Latest US Election stories

Dozens of election security experts on Monday released a letter saying claims of major hacks were unsubstantiated and absurd.

Twitter slapped warning labels on Mr Trump's posts, noting: "This claim about election fraud is disputed."

Mr Krebs headed the Department of Homeland Security's Cybersecurity and Infrastructure Security Agency (CISA) from its inception two years ago.

He angered the White House over a website run by CISA dubbed "Rumor Control," which debunks misinformation about the election, according to three people familiar with the matter.

A CISA spokesperson said the agency had no comment.

Mr Krebs was not given notice of Mr Trump's plan to fire him, according to a person familiar with the matter, and learned of the decision through Twitter.

Matthew Travis, Mr Krebs' deputy and the number two at the agency, resigned last night.

CISA Executive Director Brandon Wales is expected to take over for Mr Krebs as the acting head of the agency today, an agency official told Reuters on condition of anonymity.

Mr Wales has served in multiple positions within the DHS under the Trump administration and is not seen as a partisan figure, said a former colleague.

The Reuters report last week prompted an outpouring of support from security experts across the country, who praised Mr Krebs for his bipartisan work in the past two years.

White House displeasure with Krebs grew over the past year, according to two former officials, as Mr Trump criticised the security of mail-in voting and Mr Krebs' agency countered by saying it represented a secure way to vote.

Mail-in balloting reached a record high this year because of concerns about the coronavirus pandemic.

On his own Twitter account, Mr Krebs did not back down, writing: "Honored to serve. We did it right. Defend Today, Secure Tomorrow." 

White House officials had previously complained about CISA content that pushed back against false claims about the election, including that Democrats were behind a mass election fraud scheme. CISA officials declined to delete accurate information.

Among other things, one associate of Mr Krebs said the White House was angry about a post rejecting a conspiracy theory that falsely claimed an intelligence agency supercomputer and program, purportedly named Hammer and Scorecard, could have flipped votes nationally.

No such system exists, according to Mr Krebs, election security experts and former US officials.

A spokesman for President-elect Biden said: "Chris Krebs should be commended for his service in protecting our elections, not fired for telling the truth."

Mr Trump's move was also quickly denounced by security officials and White House critics.

"Krebs was doing important work defending critical infrastructure and fighting disinformation," said Harri Hursti, an expert on electronic voting security. "His firing is very disappointing and appears to be an attempt to undermine the great work he and others at DHS/CISA have been doing."

Democrat Adam Schiff, who heads the House of Representatives Intelligence Committee, said: "The CISA and Director Krebs have worked diligently to safeguard our elections, provide vital support to state and local election officials, and inform the American people about what was true and what was not."

Independent Senator Angus King said Mr Trump was "firing Mr Krebs for simply doing his job".

"I hope that President-elect Biden will recognise Chris's contributions, and consult with him as the Biden administration charts the future of this critically important agency," Mr King said.

Senator Ben Sasse, who has been a Trump critic, was among the first Republicans to push back against the decision.

"Chris Krebs did a really good job - as state election officials all across the nation will tell you - and he obviously should not be fired," Mr Sasse said in a statement.