And it boosted the New York Mets into a one-game lead over the Chicago Cubs in the NL wild-card race.
The Mets also lead the San Francisco Giants by two games for the wild-card playoff berth. The Dodgers fell eight games back with 26 games remaining.
After fouling off three pitches, Alfonzo hit a 2-2 pitch into the left-center field seats for his 12th homer.
Shaw (3-8), a loser to the Mets for the second time in as many days, retired pinch-hitters Lenny Harris and Matt Franco before Tony Phillips drew a walk, setting the stage for Alfonzo.
It was what Harris and Franco did before being retired that caught the attention of the Mets.
"Those two at-bats are what got that pitch to Alfonzo," manager Bobby Valentine said, referring to several foul balls hit by Harris and Franco. "They did whatever they could without actually getting a hit."
Shaw, who pitched two innings and used 31 pitches in a 5-4, 10-inning loss Friday night, needed 34 in this game his fifth in six days and third loss during that time.
After retiring Harris and Franco, Shaw walked Phillips on five pitches.
"I knew this guy was a little tired, he threw a lot of pitches," said Alfonzo, who has hit six homers in his last 26 games. "The first two guys worked him pretty good."
Alfonzo said he didn't believe it was his first game-winning homer, but couldn't remember hitting another.
"I knew I hit it pretty good, with the good spot on the bat," he said. "This feels great. I've got two strikes, I'm just trying to hit the ball somewhere. When you don't expect a home run, it will come."
Harris said he sees a big difference in Shaw.
"It seems like he's wearing down," Harris said. "He's a workhorse and everything. To me, it seems like he needs about a week off. I've seen him throw the ball a lot better than he has the last two days.
"Today, his balls didn't have nothing. Who knows, maybe he is tired. He's not the same Jeff Shaw I played with in Cincinnati."
Shaw, who has 38 saves and a 2.26 ERA, was traded by the Reds to the Dodgers on July 4. He has 15 saves since the trade.
"I'm getting a little tired," he admitted. "Those were a couple of tough days mentally, yesterday and today. It's the dog days."
Shaw credited Alfonzo as being a good hitter, and disagreed with Harris' assessment.
"When there's a save opportunity, I'm not going to turn it down," Shaw said. "Today, they asked me what I had in m, I'm going to tell the truth. I said one inning.
"I haven't lost anything on the radar readings. That will pretty much tell you."
Al Leiter (13-5) won for the 10th time in 12 decisions, allowing five hits and three runs in eight innings. John Franco blanked the Dodgers in the ninth for his 30th save.
The Dodgers got all their runs on solo homers in the first two innings to take a 3-1 lead.
Trenidad Hubbard hit his fifth homer in the first, and Raul Mondesi and Bobby Bonilla opened the second with consecutive home runs the 29th for Mondesi and the ninth for Bonilla.
The Mets had tied it at 1 in the second when former Dodgers slugger Mike Piazza hit a ground-rule double and scored on a single by Jermaine Allensworth.
The Mets moved within 3-2 in the fifth when Leiter hit a one-out double, took third on a single by Phillips and scored on a single by Alfonzo.
Former Met Brian Bohanon pitched the first eight innings for the Dodgers, scattering 11 hits while walking two and striking out four. He was lifted for a pinch-hitter in the eighth.
"We couldn't get that 27th out," Dodgers manager Glenn Hoffman said. "We've been going to Shaw a lot, and they just fouled an awful lot of pitches. Shaw's been the guy. I know I've taxed him, but (Antonio) Osuna's arm has been sore and I've needed to use him."
©1998 The Associated Press. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed