FBI director Christopher Wray has said he will resign at the end of Joe Biden's term in January, before Donald Trump comes into office.
The announcement comes less than two weeks after the president-elect said he intended to nominate loyalist Kash Patel for the job.
In a town hall meeting, Mr Wray said that he would be stepping down "after weeks of careful thought".
Trump's complete cabinet - who's in and who's out
This means he will leave three years short of completing his ten-year term, a time marked by high-profile and politically charged investigations - including FBI agents executing a search warrant of Mr Trump's Florida home in 2022.
Mr Trump has repeatedly complained about Mr Wray, including in a recent television interview with NBC News' Meet The Press.
During it, he said: "I can't say I'm thrilled with him. He invaded my home," in reference to the FBI search of his Mar-a-Lago property as part of a federal investigation into Trump's handling of classified documents - a case that has since been dropped.
By stepping down before being fired, Mr Wray said he was trying to avoid a collision with the incoming administration that would have further politicised the FBI and dragged it "deeper into the fray".
Mr Wray told employees: "My goal is to keep the focus on our mission - the indispensable work you're doing on behalf of the American people every day.
"In my view, this is the best way to avoid dragging the bureau deeper into the fray, while reinforcing the values and principles that are so important to how we do our work."
Mr Trump appointed Mr Wray in 2017 after sacking the former head of the FBI, James Comey, following the bureau's investigation into Russian interference in the 2016 US election and alleged collusion with the Trump presidential campaign.
Mr Wray was supposed to serve a ten-year term - a length meant to protect appointees from the political influence of changing administrations.
When asked about the resignation, Mr Patel said: "We look forward to a very smooth transition at the FBI and I'll be ready to go on day one."
Meanwhile, Mr Trump said Mr Wray's resignation marked a "great day".
Read more from Sky News:
Jamie Foxx reveals why he was in hospital
Russia tells citizens to avoid travel to the West
World Cup hosts in 2030 and 2034 confirmed
He added: "I just don't know what happened to him."
Mr Wray rarely seemed to go out of his way to confront the White House while in office but did break with it notably on occasion.
(c) Sky News 2024: FBI director Christopher Wray to resign before Donald Trump becomes president