Gonzalez hit an RBI single in San Diego's two-run ninth inning, lifting the Padres to a 3-2 victory over the woeful Baltimore Orioles on Friday night.
It was Gonzalez's second game-ending hit of the season and San Diego's eighth win in its final at-bat at home.
"We definitely go into these situations believing we are going to be successful," Gonzalez said. "We believe in ourselves from the beginning."
San Diego improved to 22-15 at its spacious ballpark and took a one-game lead in the NL West over the Los Angeles Dodgers, who lost 10-6 at Boston.
"This club never gives up," said David Eckstein, who hit a tying RBI single in the ninth. "We have found ways to come through. It's definitely a good feeling."
The Padres have 10 wins overall in their final at-bat.
"I didn't get a pitch near the strike zone," Hernandez said about Headley's leadoff walk. "He didn't even have to bring a bat up the plate."
Gonzalez, who went 3 for 3 with a walk, hit Hernandez's next pitch to right to give San Diego the win.
"I'm looking for a fastball and to get on top," Gonzalez said. "He gave me a pretty comfortable pitch and I was ready for it."
Gonzalez's other game-ending hit was a grand slam in the 11th inning of a 5-1 win over the New York Mets on May 2.
The Orioles have lost 11 of their last 12 games away from Camden Yards and are a major league-worst 7-28 on the road this year. They have lost 18 of 21 overall.
"That's a very, very hard one to digest," manager Juan Samuel said. "But you have to give those guys on the other side credit. They don't give up."
Heath Bell (3-0) got the win despite allowing Julio Lugo's tiebreaking bloop single in the ninth. With two out, Lugo sent a fly ball into shallow left field and Scott Hairston tried for a diving catch. But the ball hit off the top of his glove, allowing Ty Wigginton to score.
Gonzalez also hit a tying RBI double off left-hander Brian Matusz in the sixth. It was just the fifth extra-base hit by a lefty batter against Matusz all season.
That was Matusz's last inning of work. He allowed six hits, struck out four and walked one.
The Orioles went ahead 1-0 when Miguel Tejada, Markakis and Wigginton hit consecutive singles off Wade LeBlanc with no outs in the fourth. But LeBlanc got Adam Jones to foul out and coaxed Matt Wieters into an inning-ending double play to limit the damage.
LeBlanc lasted 6 2/3 innings and yielded seven hits and a walk.
The Orioles almost had another run in the fifth. Lugo led off with a single and stole second. When Lugo took off for third on the next pitch, catcher Yorvit Torrealba threw the ball down the line and into foul territory, allowing Lugo to come home.
But plate umpire Chris Guccione ruled Cesar Izturis, who was backing out of the batter's box, interfered with Torrealba as he made the throw toward third. Izturis was ruled out for interference and Lugo was sent back to second.
Despite the solid start, Matusz is 0-5 with a 5.27 ERA in his last eight starts. ... Markakis went 2 for 3 against LeBlanc and leads all left-handed hitters in the majors with a .375 batting average (33 for 88) against lefty pitchers. ... Padres LF Kyle Blanks said his ailing left elbow feels worse then when he went on the 15-day disabled list on May 20. Blanks, who had been on a rehab assignment at Triple-A Portland, was back in San Diego after undergoing another MRI.