Barr will leave the position Dec. 23 "to spend the holidays with his family" after serving as attorney general since 2019, Trump said in a tweet Monday afternoon.
"Our relationship has been a very good one, he has done an outstanding job!" Trump wrote.
Trump said that Deputy Attorney General Jeff Rosen will become acting attorney general, while Richard Donoghue will take on the duties of Deputy Attorney General.
In his resignation letter, Barr said he was greatly honored to have served in Trump's administration and praised the president's accomplishments since taking office.
"I am proud to have played a role in the many successes and unprecedented achievements you have delivered for the American people," he wrote.
Barr was sworn in as attorney general in February 2019, replacing Jeff Sessions who resigned upon a request from Trump. He had previously served as attorney general under President George H.W. Bush in 1991.
During the Trump administration, Barr oversaw the release of special counsel Robert Mueller's investigation into Russian collusion and interference in the 2016 presidential election.
The announcement of his departure also came shortly after the electoral college affirmed President-elect Joe Biden's victory in November's presidential election.
Barr also contradicted the president's claims seeking to discredit the 2020 election process, saying in an early December interview that the Justice Department had not found evidence of large-scale voter or election fraud that would overturn Biden's victory.