"We thank Attorney General Jeff Sessions for his service, and wish him well!" Mr Trump tweeted on Wednesday.
The president had repeatedly criticised his top law enforcement official after he recused himself from the Russia investigation dogging the White House.
Mr Trump said Mr Sessions will be temporarily replaced by his chief of staff, Matthew Whitaker, who has criticised the Russia inquiry.
In a resignation letter, Mr Sessions - a former Alabama senator who was an early supporter of Mr Trump - made clear the decision to go was not his own.
"Dear Mr President, at your request I am submitting my resignation," he wrote in an undated letter.