"Donald Trump is the first president in my lifetime who does not try to unite the American people – does not even pretend to try.
Instead, he tries to divide us," Mattis wrote in a statement published by the Atlantic.
While Trump has threatened to invoke the Insurrection Act and use active-duty troops to quell unrest, Mattis said the military should only be used at home on "very rare occasions" when requested by state governors.
"When I joined the military, some 50 years ago, I swore an oath to support and defend the Constitution," Mattis wrote.
While Mattis does not mention Esper by name, he also rejects the defence secretary's characterisation this week of American cities as a "battlespace" that the military can help "dominate".
"Donald Trump is the first president in my lifetime who does not try to unite the American people - does not even pretend to try."