Don McGahn, who has advised Trump in handling the Russian investigation of special lawyer Robert Mueller, has also been extensively interviewed as a collaborating witness by Mueller's team.
He will leave his post at the White House "in the fall," Trump said on Twitter.
The 50-year-old lawyer is one of the few people left in the White House who played a leading role in Trump's election campaign, where McGahn was general counsel.
His replacement, according to media reports, could be his current vice president of the White House, Emmet Flood, a Washington veteran who represented President Bill Clinton when he faced impeachment in the late 1990s.
Trump also maintains a team of private attorneys led by former New York Mayor Rudy Giuliani to address his personal legal problems.
Helped to fill the courts with conservatives
McGahn's departure will come "shortly after the confirmation (hopefully) of Judge Brett Kavanaugh before the Supreme Court of the United States," Trump said.
"I have worked with Don for a long time and I really appreciate his service!" he added.
As the official legal adviser to the president, McGahn has provided excellent service to Trump, advising him on relations with Congress and the Department of Justice, as well as how to deal with Mueller.
It has also been at the center of one of the Trump administration's greatest political successes: locating dozens of pro-Republican conservative judges in the Supreme Court and other federal courts throughout the country.
McGahn was instrumental in the Trump nomination of Neil Gorsuch and Brett Kavanaugh, judges with strong conservative records, before the Supreme Court.
But his personal relations with Trump have been formal and, at times, irritating, as he has tried to protect the president from a series of accusations and investigations into his personal behavior, his business and the alleged collusion of his campaign with the Russians at the 2016 elections.
According to media reports, McGahn has struggled to prevent the president from acting on his impulses to interfere dangerously in Russia's investigation.
He also had to mediate in the deep tensions between Trump and the Department of Justice for the investigation.
According to the New York Times, McGahn threatened to leave in June 2017 instead of fulfilling Trump's directive to fire Mueller, only a few weeks after he was appointed.
McGahn has also backed down when Trump tried to overthrow Attorney General Jeff Sessions, also out of frustration with Mueller's investigation.
Witness against Trump?
Those and other episodes, including the dismissal of FBI Director James Comey, have made McGahn a potentially important witness, as Mueller examines whether Trump illegally tried to impede the investigation, an offense that could lead to impeachment.
Earlier this month, The New York Times reported that McGahn had "cooperated extensively" with Mueller's team, participating in at least three interviews for a total of 30 hours.
Trump, who repeatedly called the investigation "rigged witch hunt," said he had authorized his team to "cooperate fully" with investigators.
But the Times said that McGahn's cooperation stemmed, in part, from the feeling that he needed to protect himself, and speculation grew quickly over whether McGahn's testimony could harm the president.
Trump suffered a double blow in court this month, when his old personal lawyer Michael Cohen pleaded guilty to campaign finance violations and former campaign manager Paul Manafort was convicted of tax and banking fraud.