US deputy attorney general Rod Rosenstein has handed in his resignation to President Donald Trump.
Mr Rosenstein oversaw special counsel Robert Mueller's investigation into alleged links between Russia and the Trump campaign before the 2016 presidential election.
He had been expected to step down in March but ended up staying in the job longer to help attorney general William Barr manage the public release of Mr Mueller's findings from his 22-month investigation.
In his resignation letter, Mr Rosenstein paid tribute to Mr Trump and even praised the president's sense of humour, despite being the subject of some of the US leader's most biting jabs.
Mr Trump once retweeted an image that showed Mr Rosenstein and other officials jailed for treason.
In a direct message to the president, Mr Rosenstein said: "I am grateful to you for the opportunity to serve; for the courtesy and humour you often display in our personal conversations; and for the goals you set in your inaugural address: patriotism, unity, safety, education, and prosperity."
Echoing one of Mr Trump's campaign slogans, he added: "We keep the faith, we follow the rules, and we always put America first."
More from US
Mr Rosenstein is due to leave his role on 11 May.
White House did not immediately comment on the resignation but noted that Mr Trump had already nominated deputy transportation secretary Jeffrey Rosen as the replacement.
Mr Rosenstein, a Republican, was often criticised by the president and his allies for appointing Mr Mueller.
The Mueller investigation did not establish evidence that Mr Trump's campaign illegally conspired with Moscow, and did not make a determination on whether the president obstructed justice.