Mr Trump said it was "a decision I totally understand and respect".
"Karoline will now be one of my top outside advisors, and an influential voice within the Republican Party, as we work to defy History, and conclusively win the Midterm Elections," he wrote on Truth Social.
Mr Trump's Republican Party faces an uphill battle to retain control of Congress after the November 3 midterms, polls show.
His personal approval rating is hovering at record lows. An Economist/YouGov poll this week put his approval rating at 33 per cent, the lowest recorded across his two terms. His disapproval rating was 62 per cent, the highest recorded.
"Our country is facing an existential threat from an increasingly extremist Democrat Party that seeks to destroy everything great about America," Ms Leavitt wrote.
"I believe it is incumbent upon all of us who care about this country to fight back against that threat. My fight is entering a new phase, but it is far from over."
Ms Leavitt was 27 when she stepped into the role at the beginning of Mr Trump's term last year, making her the youngest press secretary in US history. She served as an assistant press secretary during his first term.
She developed a reputation as a loyal and unashamedly combative spokeswoman for Mr Trump's policies. She frequently clashed with reporters who posed critical questions, and was a fierce proponent of Mr Trump's baseless insistence he won the 2020 election.
