Kyle Blanks hit a two-run homer and made a great catch in left field, but it was the effort from San Diego's bullpen that proved key.
Five relievers combined to limit the Marlins to two hits in 3 2/3 innings. But there was perhaps no moment bigger than when Hamren came in to protect a 4-2 lead with the bases loaded and one out in the sixth inning in relief of Wade LeBlanc.
"Hamren got thrown into the fire against one of the best young hitters in the game," San Diego manager Bud Black said about the duel with Stanton. "He responded and made pitches. It should be a great learning experience and a confidence builder as well."
Hamren, who made his major league debut Aug. 1, acknowledged he's still learning not to be star-struck.
"I'm starting to move beyond that," Hamren said. "I'm starting to get more settled now, a little more comfortable. But it always lingers in the back of your head. But you just try to push that aside as much as possible."
Stanton homered in four straight games coming into Thursday's series opener. He is among the NL leaders with 27 homers and 76 RBIs. Stanton was a late scratch from the lineup with a sore left big toe.
"I did my job because I kept the lead," Hamren said. "Obviously, you don't want to give up any runs coming in. As long as we still came out with the lead, you learn to live with some mistakes because you're not going to be perfect all the time."
Hamren has seen action in eight innings over seven games since coming up from Double-A San Antonio. He is part of a young bullpen that will get a chance to prove themselves.
"We're finding out about guys," Black said. "For a lot of players, every day is a job interview. I think these guys sense that."
Blanks crushed a ball into the second deck in left field to put the Padres ahead to stay 3-2 in the fourth inning. The 6-foot-6 Blanks also made a running catch to rob Sanchez of an extra-base hit in the fifth inning.
The Padres handed Florida its 13th loss in 15 games. San Diego won its fifth straight over the Marlins this season, outscoring them 30-10.
LeBlanc (2-2) had a shaky outing but the bullpen held the Marlins in check to give San Diego its fourth win in six games after dropping four of the previous six.
Heath Bell pitched the ninth for this 34th save in 37 chances.
Blanks' towering shot off Chris Volstad (5-10) was his fourth. Volstad has allowed 20 homers in 22 starts this season.
"It's been pretty common," Volstad said. "I hung a slider to (Blanks) for two runs. It was a tough one. It's getting pretty frustrating for me."
Jose Lopez had three doubles to tie a Marlins record and drove in a run in the first inning. Volstad added an RBI double in the fourth. Florida stranded 12 base runners.
LeBlanc won his second straight start after having gone eight starts without a win, dating back to last August. The lefty allowed three runs on six hits over 5 1/3 innings. He walked four and struck out three.
Volstad lasted five innings after giving up four runs on six hits with seven strikeouts and one walk.
San Diego has hit a major league-low 69 home runs. ... Stanton hurt his left big toe Thursday night when he jammed it against the right-field wall while chasing Nick Hundley's triple. ... Petco Park sported two large logos in foul territory down the first and third base lines in commemoration of Sunday's retirement ceremony for Trevor Hoffman, baseball's career saves leader. ... Marlins RHP Edward Mujica pitched for the first time since Monday night when he left with a sore right lat muscle. ... On Saturday, Florida right-hander Clay Hensley (1-4, 4.53 ERA) will make his first start and third appearance against his former team when he faces Padres' right-hander Aaron Harang (11-3, 4.08), who is 6-1 over his last 13 starts.