The club confirmed the news on Monday evening, amid reports former Spain, Real Madrid and Wolves boss Julen Lopetegui had agreed a deal to take over in the summer.
Moyes said: "I have enjoyed four and a half brilliant years at West Ham, and the club is in a stronger position than when I returned back in 2019.
"When I joined West Ham for a second time, the club was one place above the relegation zone, and it has been a terrific journey to have achieved three consecutive seasons in Europe.
"After leading the club to safety, we guided the team to finishes of sixth and seventh in the Premier League, and I was delighted when we won the Europa Conference League title last June - the club's first major trophy in 43 years.
The Hammers said the recruitment process for Moyes' successor had begun and they would make no further comment on the matter until the new appointment was confirmed.
Joint chairman David Sullivan said on the club's website: "On behalf of everyone at West Ham United, I would like to offer our sincere thanks and gratitude to David for the contribution he has made to the football club during his time as manager.
"David has been responsible for a period of great progress and success in our history, and we are extremely grateful for all of his hard work, commitment and dedication to the role."