Mr Barr’s term was due to end on 20 January, when Mr Trump leaves office. Tensions between the two flared after Mr Barr said there was no evidence of widespread fraud in November’s vote.

He was criticised by Mr Trump for not publicly disclosing during the election campaign that the justice department was investigating Joe Biden’s son.

Mr Trump tweeted Mr Barr’s resignation letter saying: “Our relationship has been a very good one, he has done an outstanding job!”

Mr Barr’s letter to the president began by saying he “appreciated the opportunity to update” the president on the Department of Justice’s (DOJ) review of voter fraud allegations in the recent election and “how these allegations will continue to be pursued”.

He did not give more details about the review, and praised Mr Trump’s achievements in office before ending the letter by saying he would depart from his position on 23 December.

Rumours that Attorney General Barr was eyeing an early exit from the Trump administration turned out to be true. Although he received a traditional Trump send-off – his departure announced via Twitter – the president was cordial, thanking him and posting his effusive resignation letter.

If there were any discord over the attorney general’s recent handling of election investigations – his assertion that he had seen no evidence of widespread fraud – it did not spill into public view.

Mr Barr probably will best be remembered for his management of Special Counsel Robert Mueller’s Russia probe. He defused what could have been a political bomb for the president by giving an advanced summary of the independent counsel’s full report in a four-page memo that downplayed many of its more serious allegations.