Arnautovic, 29, had been the subject of a £35m bid from a Chinese club offering wages of around £200,000 a week.
He was said to have wanted the move but on Friday the Austrian international “put a stop” to speculation by committing himself to the Hammers.
West Ham announced the deal less than an hour after being knocked out of the FA Cup by AFC Wimbledon.
Arnautovic did not play in the 4-2 defeat away to the League One side.
“I want to say to the fans that I’m happy to stay,” said the striker in a statement released by West Ham. “I’m glad to play again, show myself and score goals, to make assists, but also to say that the major point is Marko Arnautovic never refused [to play or train]. I would never refuse.”
He added: “The fans gave me the power, they gave me the energy and that’s why I have to be here and that’s why I want to stay. I never wanted to run away because I hate this club, this was never my intention.”
The club did not reveal the length of the contract extension.
Arnautovic, who moved to London Stadium from Stoke in 2017 for a then club record £20m after handing in a transfer request at the Potters, was already under contract until 2022.