Of these, 2.75m said they are not in the jobs market because of long-term sickness, up from around 2m in 2019, before the pandemic.
It takes potential workers away from jobs, harming the economy and hurting the public finances, as well as damaging the prosperity and life chances of those individuals.
The rising prevalence of poor mental health is thought to be a major factor behind the increase.
Just over half of those inactive with long-term sickness last year said they had depression, bad nerves or anxiety, the ONS found.
The NHS said that in 2023 its mental health services treated a record 3.8m, up by more than one third compared with 2018-19, before Covid.
The UK Health Security Agency said building “psychosocial resilience in the face of a changing climate” is key to easing the burden.
“Mental health can be impacted both directly and indirectly by climate change through various pathways from exposure to acute extreme weather events and slower-onset, longer-lasting events.
“Climate change can also have psychological implications through growing awareness of the issue, leading to psychological distress,” the UK Health Security Agency said.
“With mental health issues already impacting a significant proportion of the UK population, climate change could exacerbate existing challenges, and introduce new challenges for population mental health and in turn, health services.
“Preparing and adapting for psychosocial resilience in the face of a changing climate will be imperative for protecting population health in the future and building resilience in the health system.”