McGahn, who has told many friends that he has wearily endured countless political and legal battles, saw Trump's tweet as abrupt but typical of how the president acts - and it did not make him angry, according to two people familiar with his reaction.
"We do everything straight", he said.
Trump later claimed to have allowed McGahn and other members of the administration to "fully cooperate" with Mueller, whose investigation the president has regularly decried as a "witch hunt" and a "hoax". Besides dealing with special counsel Robert Mueller's investigation, McGahn has had important input on a range of issues from policy to personnel to national security.
McGahn "will be leaving his position in the fall, shortly after the confirmation (hopefully) of Judge Brett Kavanaugh to the United States Supreme Court", Trump said Wednesday.
The lawyer has reportedly sat for three voluntary interviews totalling 30 hours with Department of Justice investigators.
McGahn also ordered his entire staff to recuse themselves from the investigation, Trump's former outside lawyer Ty Cobb said.
McGahn voluntarily cooperated with Special Counsel Robert Mueller and his team in a continuing investigation that already has resulted in guilty pleas, indictments, cooperation deals and one conviction for several Trump insiders.
McGahn has been something of a shadow figure, gaining little personal spotlight in the tumultuous atmosphere surrounding Trump's White House.
In a statement to ABC News, Grassley's spokesman said the senator's tweet reflected his admiration for McGahn's work regarding judicial nominees.
McGahn has played a leading role in the White House's efforts to shape the judiciary. He called the departure "sad news for our country".
Axios says McGahn would like to be succeeded by Emmet Flood, the attorney who represented President Bill Clinton during his impeachment trial and joined Trump's legal team to "represent the president and the administration against the Russian Federation witch hunt", as White House press secretary Sarah Huckabee Sanders put it in May.