"As my scheduled time as a Special Government Employee comes to an end, I would like to thank President @realDonaldTrump for the opportunity to reduce wasteful spending," Musk wrote on X.
"The @DOGE mission will only strengthen over time as it becomes a way of life throughout the government."
The South African-born tech tycoon had been designated as a "special government employee" - allowing him to work a federal job for 130 days each year.
Measured from Trump's inauguration on 20 January, he would hit that limit towards the end of May.
But his departure comes a day after he said he was "disappointed" with Trump's budget bill, which proposes multi-trillion dollar tax breaks and a boost to defence spending.