Speaking at a New York charity event Thursday the day after Trump demeaned him as "the world's most overrated general," Mattis joked that he took it as a compliment.
"I'm not just an overrated general. I'm the greatest, the world's most overrated," he told diners at the annual Alfred E. Smith Memorial Foundation Dinner.
Trump lashed out at his former defense secretary Wednesday, during a contentious White House meeting with members of Congress.
Before the walkout, Trump disparaged Mattis, who had argued as defense secretary that U.S. troops were needed in Syria to prevent a resurgence of Islamic State fighters.
Trump said Mattis was "the world's most overrated general. You know why? He wasn't tough enough."
"I captured ISIS," Trump went on to say.
Mattis resigned as defense secretary last December after Trump said he intended to pull 2,000 American troops out of Syria. In his resignation letter, the retired Marine general told Trump he had "the right to have a Secretary of Defense whose views are better aligned with yours."
Since then, he has largely refrained from publicly criticizing the administration, saying he owed the commander in chief "a duty of silence."
But he did save a zinger for Trump at the laughter-filled gala, saying the "overrated" moniker didn't bother him.
"I earned my spurs on the battlefield ... and Donald Trump earned his spurs in a letter from a doctor," Mattis joked.
On a serious note, Mattis alluded to Trump's decision to have U.S. troops stand down in Syria, clearing the way for Turkey to launch an offensive against Kurdish forces who had been U.S. allies in the fight against the Islamic State group. On Thursday, the U.S. and Turkey agreed to a five-day cease-fire that requires the Kurdish fighters to vacate, largely solidifying Turkey's position in the region.
"We owe a debt to all who fought for liberty, including those who tonight serve in the far corners of our planet, among them the American men and women supporting our Kurdish allies," Mattis said.
The annual gala draws luminaries from finance and politics. Hosted by Cardinal Timothy Dolan, the archbishop of New York, the benefit is named after a former New York governor who was the first Catholic to receive a major party nomination for president in 1928, before losing the general election.