In the letter, Sessions said he was departing as head of the Justice Department at the president's request.
"Since the day I was honored to be sworn in as attorney general of the United States, I came to work at the Department of Justice every day determined to do my duty and serve my country," Sessions wrote. "I have done so to the best of my ability, working to support the fundamental legal processes that are the foundation of justice."
Trump said Sessions' chief of staff, Matthew Whitaker, would take over as acting attorney general.
"We thank Attorney General Jeff Sessions for his service, and wish him well!" Trump said in a tweet. "A permanent replacement will be nominated at a later date."
Sessions took the oath of office as Trump's first attorney general Feb. 8, 2017.
The two butted heads when shortly after, Sessions recused himself from overseeing the Russia investigation of special counsel Robert Mueller. His recusal came after it was revealed he didn't disclose a meeting with former Russian Ambassador Sergey Kislyak during his confirmation hearings.
Trump said he never would've nominated Sessions to be attorney general if he knew he would recuse himself. The president repeatedly took shots at Sessions over the probe during rallies, interviews and on Twitter.
"The Russian Witch Hunt Hoax continues, all because Jeff Sessions didn't tell me he was going to recuse himself...I would have quickly picked someone else. So much time and money wasted, so many lives ruined...and Sessions knew better than most that there was No Collusion!" he wrote on Twitter in June.
Sessions' recusal left Deputy Attorney General Rod Rosenstein to oversee Mueller's probe into alleged Russian meddling in the 2016 election. With Sessions' departure, Whitaker will take over oversight of the probe, Justice Department spokeswoman Sarah Isgur Flores told The Hill.
Before serving on Trump's Cabinet, Sessions was a Republican senator representing Alabama from 1997 to 2017. He served as Alabama's attorney general from 1995 to 1997.
"I am particularly grateful to the fabulous men and women in law enforcement all over this country with whom I have served," Sessions' letter to Trump said. "I have had no greater honor than to serve alongside them. As I have said many times, they have my thanks and I will always have their backs."