Taylor Richards had opened the scoring for the visitors on 19 minutes, but the Hammers were level on the half-hour mark thanks to Nathan Holland.
There was plenty of chances for both sides, with West Ham looking most likely to snatch a winner through Martinez (pictured).
Then, with seven minutes remaining, the 20-year-old striker produced the decisive goal with a low drive into the bottom corner.
The win takes the Hammers up to third place in Division 1, while Man City drop to seventh.
WHU: 31 Oct v Bristol Rovers (A) – Checkatrade Trophy
MCI: 18 Nov v Man Utd (A) – Premier League 2