The former Goldman Sachs president and free trade advocate Cohn, whose departure date will come in a few weeks, decided to quit after Trump announced he would impose stiff tariffs on steel and aluminum imports.
In a prepared statement, Cohn said, "It has been an honor to serve my country and enact pro-growth economic policies to benefit the American people, in particular the passage of historic tax reform."
"I am grateful to the President for giving me this opportunity and wish him and the Administration great success in the future," Cohn said.
In his own statement, Trump said, "Gary has been my chief economic advisor and did a superb job in driving our agenda, helping to deliver historic tax cuts and reforms and unleashing the American economy once again.
"He is a rare talent, and I thank him for his dedicated service to the American people."
Cohn clashed with Trump's protectionist advisors on the issue of tariffs.
At a meeting with steel and aluminum executives last Thursday where Trump announced the move, Cohn argued against it, warning about price increases for steel and aluminum products, according to a person in the room.
An Axios reporter Thursday reported via Twitter that last Thursday Trump canceled a meeting that Cohn arranged for him with companies that use steel and aluminum in their products, in an effort to dissuade the president from imposing the tariffs.
However, White House officials told CNBC earlier Tuesday that if Cohn were to resign it would not be only due to the president's decision on tariffs.
Market watchers saw Cohn's potential departure as a bad omen for the White House's economic policy. He helped to shepherd massive tax cuts, the Trump administration's only major legislative achievement, which the president signed into law in December.
Cohn also faced pressure to step down following Trump's defiant response to violence at a white nationalist rally in August. In an FT interview published that month, Cohn said he faced pressure both to leave Trump's White House and to stay in it. He even drafted a resignation letter, according to The New York Times.
The economic advisor told the FT that the White House "must do better" following Trump's widely criticized response to violence at the white nationalist rally in Charlottesville, Virginia.
The interview may not have helped his case with the president.
The president's chaotic Trump Tower press conference in which Trump appeared to equate torch-bearing white nationalists with the protesters who demonstrated against them also fueled the possibility of Cohn, who is Jewish, resigning. "Not all" the people participating in the rally were bad, the president told reporters three days after a counterprotester was killed in a car ramming, allegedly by a suspected white supremacist.
"Citizens standing up for equality and freedom can never be equated with white supremacists, neo-Nazis, and the K.K.K.," Cohn told the FT. "I believe this administration can and must do better in consistently and unequivocally condemning these groups and do everything we can to heal the deep divisions that exist in our communities."
Cohn was Goldman's no. 2 executive when Trump named him as his top economic advisor. Trump offered the former Goldman Sachs president the key economic post on Dec. 9, despite bashing the firm during the 2016 campaign. Cohn also had been seen as a possible chairman of the Federal Reserve.
CNBC's Eamon Javers contributed to this report.