Goldschmidt hit his 30th homer, Greinke won for the first time in almost a month and the Diamondbacks avoided a three-game sweep at the hands of Seattle by beating the Mariners 5-2.
With the victory and Colorado's 12-3 loss to St. Louis, the Diamondbacks were back alone in first place in the NL West, a game up on the Rockies and 2 1/2 ahead of the Los Angeles Dodgers. Houston beat the Los Angeles Angels 3-1, so Seattle fell 6 1/2 behind the Astros in the AL West.
"This is an amazing game, and you can't take anything for granted," Diamondbacks manager Torey Lovullo said. "We fumbled a couple of balls out there and that leads to a couple of runs, but when we had to, we made pitches and made plays and won a very tough game.
"When I tell you today was hard, that was probably an understatement after what we walked through last night."
Goldschmidt's three-run shot off Mike Leake (8-8) punctuated a five-run third inning for the Diamondbacks, who bounced back from blowing a two-run lead in the ninth Saturday night and losing in 10 innings.
Arizona flirted with losing this one in the ninth, too. Ben Gamel and Chris Herrmann opened the inning with singles off Yoshihisa Hirano and left fielder David Peralta dropped Dee Gordon's line drive to allow a run to score.
Brad Boxberger, who blew the save Saturday night, came in and walked pinch-hitter Nelson Cruz to load the bases. But Mitch Haniger lined out sharply to third and Robinson Cano bounced into a double play to give Boxberger his 29th save in 35 tries.
"We did put some pressure on them, had our chances there late," Mariners manager Scott Servais said, "just not enough."
Greinke (13-8) gave up an unearned run and five hits in 6 2/3 innings, striking out six and walking two. He had gone 0-3 in his previous four starts.
Leake fell to 0-4 in his last 10 starts and hasn't won since June 23 despite several strong outings in that span. He was tagged for five runs and seven hits, striking out six in six innings Sunday.
"It's part of the game," he said of the long stretch without a win. "There's ups and downs. It's what you learn throughout your career. It's just part of it and you've just got to keep doing a good job."
Jeff Mathis, Greinke and Jon Jay loaded the bases with one-out singles in the third. A.J. Pollock brought the tying run home with a sacrifice fly and David Peralta made it 2-1 with a slow-rolling RBI infield single.
Peralta's was the key hit of the inning, Servais said, "an extra out."
That brought up Goldschmidt, who was 1-for-10 in the series before sending Leake's pitch deep into the left field seats.
It is Goldschmidt's fourth career 30-homer season.
"Honestly, it's not something I'm thinking about," he said. "We're obviously here in a playoff race and just trying to find a way and go out and perform and help us win. Even if I don't do that (hit 30 homers) and the team wins, that's most important."
Seattle got an unearned run in the first when Haniger reached on shortstop Ketel Marte's throwing error. With two outs, Haniger advanced to second on Denard Span's single and scored when Kyle Seager singled.
Mariners: Leake was scratched from his last scheduled start Aug. 21 because of illness.
The Diamondbacks showed a video tribute to Arizona Sen. John McCain, who died Saturday of brain cancer. McCain was a fan of the team and a regular at games until his illness forced him to stay away. The tribute even included a repeat of McCain's tweet after the Dodgers celebrated clinching the pennant with a dip in the Chase Field swimming pool, calling it a "no class act by a bunch of overpaid, immature, arrogant, spoiled brats."
After the video, there was a moment of silence for McCain. A No. 18 jersey with the name "McCain" hung in the Diamondbacks' dugout.
In a statement, Diamondbacks President and CEO Derrick Hall said, "I am honored to consider him a friend and we will miss seeing his smiling face in the stands."
More AP MLB: https://apnews.com/tag/MLB and https://twitter.com/AP-Sports
Could these 'mystery teams' be in on Manny Machado, Bryce Harper?
Are the Yankees set to swoop in on Manny after all? Who might be biding their time for Bryce? We look at some of the potential surprise suitors insiders are talking about.
'I came up on one-year deals': How Joe Maddon is approaching 2019
As the skipper enters his potential final year in Chicago, Maddon is leaving no stone unturned as he tries to get the Cubs back on track after a disappointing finish and a quiet offseason.
Will Bryce Harper and Manny Machado sign before Super Bowl Sunday and other burning questions
With the offseason providing few answers for baseball's superstar free agents, we shed some light on where things stand and where they're headed.
Red Sox unlikely to spend big to sign closer, Dave Dombrowski says
Boston Red Sox manager Alex Cora, a Puerto Rico native who has been outspoken about its need for hurricane relief, indicated on Thursday that he may skip the World Series celebration at the White House over President Donald Trump's policies toward the...
Cubs GM: Giving second chance to Addison Russell 'was the right thing to do'
Cubs owner Tom Ricketts said the team decided it would rather support Addison Russell after his suspension for violating the league's domestic abuse policy rather than "just cut him."
Yankees, Adam Ottavino agree to 3-year, $27 million deal
Free-agent reliever Adam Ottavino, who had a breakout 2018 season as the setup man for closer Wade Davis with the Rockies, has agreed to sign with the Yankees, sources told ESPN.