The Italy international made 204 Premier League appearances for the club and was part of their Europa Conference League-winning side last year.
The former Juventus player struggled with several injuries during his time at West Ham, including a cruciate ligament tear suffered in 2021 that kept him out for almost a year.
"When he was not playing, Ogbonna was always a willing supporter of the club's community work," West Ham said in a statement. "He will always be a beloved member of the West Ham United family."