For most of the night, it seemed just about everything conspired against New York City FC, whether it was the superb goalkeeping of Tim Melia, the woodwork or even a teammate being at the wrong place at the wrong time.

Finally, Jack Harrison found himself at the right place, scoring the winning goal in the 84th minute to lift City to a hard-earned 1-0 victory over Sporting Kansas City before a rain-soaked crowd of 19,353 at Yankee Stadium Wednesday night.

Considering NYCFC was missing four starters, including MLS leading goal-scorer David Villa, it was a big win.

The result moved second-place NYCFC (15-7-5, 50 points) within six points of first-place Toronto FC (16-3-8, 56) in the Eastern Conference and gave the hosts a six-point cushion over the third-place Chicago Fire (13-9-5, 44) with seven games remaining in the regular season.

“What really made me proud about the win today was the consistency of the performance,” coach Patrick Vieira said. “It didn’t matter who was playing.”

RJ Allen floated a right-wing cross in the penalty area to an unmarked Harrison, who sent a bouncing shot to the far right post past Melia.

“I don’t think it was his best game,” Vieira said. “I think he made a lot of mistakes in the last 30 yards. Of course, when you have talent, you can open up the game.”

advertisement | advertise on newsday

Until Harrison tallied his ninth goal of the season, the game appeared headed for a scoreless draw as neither side could find the range.

NYCFC midfielder Maxi Moralez had to be the most frustrated player as he was denied by Melia, the right post and even teammates. Melia, a graduate of East Islip High School, saved the Argentine midfielder’s attempt a minute into first-half stoppage. Moralez drilled a shot off the right post in the 54th minute before he was thwarted by two teammates in the 65th minute. His shot from the right side barely deflected off Sean Okoli and was inadvertently blocked by Khiry Shelton. Shelton wound up in the back of the net, but the ball didn’t.

NYCFC had nine players missing because of international duty, injury or suspension.

The most promiment were four regulars who participated in World Cup qualifiers: Villa (adductor muscle); defensive midfielder Alex Ring (toe); forward Rodney Wallace, in a double jeopardy because of a yellow-card suspension, and midfielder Yangel Herrera, who started in Venezuela’s 1-1 draw at Argentina Tuesday.