The former Everton and Manchester United manager is in his second spell with the Hammers.
Moyes guided a struggling West Ham side to safety after taking over from Slaven Bilic in November 2017 but his short-term contract was not renewed at the end of the season.
He returned to the London Stadium in December 2019 to replace Manuel Pellegrini and has led the Hammers into next season’s Europa League via a sixth place finish in the league last season.
"I am delighted to have committed my future to West Ham United," said Moyes.
"This is where I want to be and I'm happy. I'm excited to be given this opportunity to build on what we all have already achieved here. The owners and I are fully aligned with how we want to keep developing and improving the football club.
"The board and everyone at the club have been fantastic to work with, giving me great support and I feel that we are all united in what we want to achieve in the coming years and how we might be able to achieve those things."
"We have made tremendous progress in the past 15 months and that has been a collective effort from everyone at the club," the 58-year-old Scot added.
"The players really have been superb but the challenge is for our standards to continue developing."