Substitute Yarmolenko, who replaced Michail Antonio in the second half, shed tears as he dropped to his knees in celebration.
He was welcomed on to the field with a warm reception from both sets of supporters, and some Aston Villa fans even applauded as he was embraced by his team-mates for the goal.
The Hammers were lifted after taking the lead and Pablo Fornals sealed victory when he powered Benrahma's cutback past Martinez.
Villa arrived in the capital off the back of three impressive wins but they had to settle for a Jacob Ramsey consolation late on.
Victory for the hosts ended a run of three defeats in all competitions and lifted them to fifth in the table, while Villa remain ninth.