NEW YORK — Through the first 14 innings of their homestand, the New York Yankees had five errors and four hits. A restless crowd was booing the team in pinstripes on a 96-degree night.

Then all of a sudden, the Bronx Bombers snapped out of it in a big way.

Pinch-hitter Neil Walker connected for a solo home run in the bottom of the ninth inning, and New York rallied from a four-run deficit to defeat the Chicago White Sox 5-4 on Tuesday.

"It's not easy for us right now," Yankees manager Aaron Boone said. "We're kind of grinding through some things. It's a tough stretch. But these guys continue to find a way."

Aaron Hicks hit a tying homer in the eighth and rookie Miguel Andujar also had a two-run shot to help the injury-depleted Yankees win for the ninth time in 11 games. With the second-best record in the majors (84-48), they remained 6½ games behind first-place Boston in the AL East.

Walker batted for Ronald Torreyes with one out and launched the first pitch he saw from Dylan Covey (4-12) way over the right-center wall for his first career pinch-hit homer and second game-ending drive. As he neared home plate, Walker tossed his helmet high in the air and was swarmed by happy teammates.

"As a pinch-hitter, you try to assume that the first pitch you see is going to be the best pitch you see. You try to be aggressive, just try to be on time," explained Walker, who acknowledged the Yankees are tired. "That's obviously as much as you can ask for tonight."

With the Yankees down by two, Giancarlo Stanton singled leading off the eighth to stop an 0-for-14 slide. Hicks drove a full-count pitch from Juan Minaya to right and shouted toward the Yankees' dugout as he trotted to first.

"Just a big relief," Brett Gardner said. "A lot of excitement."

Dellin Betances (4-3) struck out two in a perfect ninth.

New York was blanked on one hit by James Shields over the first five innings. Gardner began the comeback with a leadoff triple in the sixth , and Andujar connected for his 22nd homer two outs later.

Shields left leading 4-2 with two on in the sixth. He remained 5-15 overall, tied with Baltimore right-hander Alex Cobb for the most losses in the majors.

"Pretty good outing overall," Shields said. "Unfortunately, my record is not really showing how I've pitched this year. Sometimes that happens. ... Overall, I'm really pleased with my season."

Flashing signs of improvement, the young, rebuilding White Sox had won four straight and 10 of 13.

"We've been playing really good baseball," Shields said. "That's a game we can't let go right there. That's a learning process for these guys, and situational pitching is very important in this game. We have to do a better job of that."

Chicago chased Yankees starter Lance Lynn with consecutive two-out singles in the sixth. Yolmer Sanchez greeted Jonathan Holder with an RBI single, and Nicky Delmonico made it 4-0 when he plopped a two-run single into left field.

Delmonico scored easily from first base in the fifth when Gardner bobbled Avisail Garcia's RBI double in left.

WHAT'S IN A NAME?

Fittingly, Walker's home run was the 80th walk-off homer in the majors this season. That matched the record set in 2004, according to Major League Baseball. "He's just a true pro," Gardner said.

MILESTONE MAN

The 36-year-old Shields threw 98 pitches in the heat but hasn't won on the road since opening day at Kansas City. It was his 400th career start. "I'm pretty proud of that," he said. "Pretty special."

TRAINER'S ROOM

White Sox: SS Tim Anderson tripped over an oncoming Delmonico on Greg Bird's eighth-inning popup, but held onto the ball. Anderson exited with a bruised left ankle and is day to day. "I'm assuming he'll be fine," manager Rick Renteria said. Anderson was replaced in the ninth by Jose Rondon.

Yankees: RF Aaron Judge said his broken right wrist remains sore to the touch and he still hasn't started swinging a bat. "It's getting better every couple of days," he said. "They told me I can play before it completely heals." The slugger was injured July 26. "It takes about six weeks for something like this to fully heal," Judge said. "I'm not that close yet. I'll wake up one of these days and feel good. I'm just waiting for that day." ... C Gary Sanchez (strained right groin) was the DH in his second rehab game with Triple-A Scranton/Wilkes-Barre. He has homered in both games. ... SS Didi Gregorius (bruised left heel) took grounders hit right at him and could begin running Wednesday. It remains to be seen whether he'll need a minor league rehab assignment before coming off the DL. ... All-Star closer Aroldis Chapman (left knee tendinitis) was scheduled to receive a second platelet-rich plasma injection Tuesday, according to Boone.

UP NEXT

White Sox: RHP Reynaldo Lopez (4-9, 4.66 ERA) makes his first start at Yankee Stadium in the series finale Wednesday night. Lopez is 0-4 with a 6.70 ERA in his last nine outings, getting a no-decision in each of the past five. But he pitched well Aug. 7 against New York, permitting one run in seven innings.

Yankees: CC Sabathia (7-4, 3.30) seeks his 245th career win. The 38-year-old lefty returned from the disabled list last Friday in Baltimore and allowed two earned runs with eight strikeouts over six innings. He racked up 12 strikeouts over 5 2/3 innings in a strong outing Aug. 7 against the White Sox.