Josef Martinez celebrates his game-winning goal with his teammates after Atlanta’s great comeback. (Kyle Terada-USA TODAY Sports)

SAN JOSE, Calif. — The Red Bulls certainly will have their work cut out for them as they strive to win the Supporters Shield in MLS.

That’s because Atlanta United FC grabbed a four-point lead in the race with five games remaining in the season in wake of its 4-3 comeback win over the San Jose Earthquakes Wednesday night.

The victory gave Atlanta (18-4-6, 60) a cushion over second-place New York (17-7-5, 56). Third-place New York City FC (14-8-7, 49) is all but mathematically out of the running.

The visitors stormed back in the second half to score three goals in the final 20 minutes to overcome San Jose Earthquakes at Avaya Stadium. Striker Josef Martinez scored twice, including the game-winner in second-half stoppage time, to become the first player in league history to reach 30 regular-season goals.

Miguel Almirón added another as Atlanta picked up its 10th road win of the season to break the league record for road victories in the post-shootout era. The triumph also secured a top four finish in the Eastern Conference, guaranteeing the club at least one home MLS Cup playoff game.

San Jose jumped out to an early lead thanks to Nick Lima in the 13th minute. The defender made a run deep into the box to join the attack and snuck to the far post to head in a cross from Shea Salinas for the 1-0 lead. A half hour later, Danny Hoesen doubled the lead after getting through on a long ball from the Earthquakes’ half. Hoesen’s shot was saved by goalkeeper Brad Guzan, but on the ensuing rebound Hoesen chipped a ball to the far post to make it 2-0.

Atlanta pulled one back before halftime with Tito Villalba sending in a screamer during first-half stoppage time. Quickly hitting on a counterattack, Martinez held up a ball for Julian Gressel, who sent a cross toward the far edge of the box for Villalba. The Argentine-born forward one-timed his shot into the upper right corner, leaving keeper JT Marcinkowski no chance to make a save.

In the 58th minute, San Jose again went up by two goals as Vako Qazaishvili maneuvered through the defense and struck with a left-footed shot into the left corner for a 3-1 lead.

The hosts appeared to take a 4-1 lead about 10 minutes later from Chris Wondolowski, but video review overturned a call on the build-up of the play, awarding Atlanta a penalty due to a handling infraction on Magnus Eriksson. Martinez stepped up to the spot and scored with a low shot to the right corner to cut the deficit to one.

Only three minutes later, Almirón equalized after latching onto a loose ball in the box. Martinez capped the comeback by heading in a cross from Almirón in the fifth minute of stoppage time for the win and his 30th goal of the season. Ezequiel Barco played Almirón free along the left wing and he immediately sent a cross for the far post that Martinez timed perfectly to head back into the net.

Atlanta hosts Real Salt Lake at Mercedes-Benz Stadium Saturday at 7 p.m. while the Red Bulls welcome defending MLS Cup champion Toronto FC to Red Bull Arena at the same time.