Hamels tossed 7 1/3 innings and allowed only five hits and two earned runs while denying Maddux career win No. 350 in his third attempt at the mark.
Hamels also ripped a single to right field off Maddux in the seventh inning and improved his batting average to a stellar .313.
"My No. 1 concern is always pitching," said Hamels, who threw 21 first-pitch strikes. "Getting a win against Greg Maddux is huge. Getting hits are extra bonuses."
Getting wins against Maddux are extra bonuses, too.
"It's nice because he's a guy I grew up with and idolized," Hamels said. "To get a hit off him is pretty special."
Hamels (3-3) turned in his team-leading fourth quality start while throwing at least seven innings in each of his six starts this season.
"He mixed his pitches and was aggressive with his fastball," Phillies manager Charlie Manuel said. "Cole didn't make too many mistakes."
Maddux was consistently around the strike zone as usual and gave up eight hits and three earned runs over 6 1/3 innings.
The Phillies, who laced 12 hits, scored two quick runs off Maddux by the third inning, highlighted by an RBI single by Eric Bruntlett in the third, scoring Jayson Werth for a 2-0 advantage.
Hamels surrendered a solo homer to Scott Hairston in the fifth, but the Phillies quickly got that run back on a deep sacrifice fly to center by Werth in the seventh, scoring Carlos Ruiz for a 3-1 lead.
San Diego got within 3-2 in the eighth when former Phillie Tadahito Iguchi grounded out with the bases loaded, scoring Hairston.
Tom Gordon then wriggled his way out of the bases loaded jam by forcing Kevin Kouzmanoff to ground out to Chase Utley, thus ending the threat.
"I told myself to just relax and make a good pitch," Gordon said. "I said to keep the ball down. I was trying to get a double play. While I didn't get a double play, I got the out. It was all positive for me."
The Phillies tacked on an insurance run when Pedro Feliz smoked an RBI single to right in the eighth, scoring Utley for a 4-2 lead. Ruiz added a two-run double to center as the Phillies broke the game open.
Utley has reached base safely in 20 straight games and in 26 of 27 games this season. With a pair of hits, he racked up his Major League-leading 15th multi-hit game this season.
With the win, the Phillies (15-12) guaranteed a winning April for the first time since 2003.
"It's huge," Hamels said. "Last year, we were able to get over the hump of not getting to the playoffs."
The Phillies activated outfielder Shane Victorino before the game and hope to see reigning National League Most Valuable Player Jimmy Rollins in the lineup by the time they begin their West Coast trip on Monday in Phoenix against the Diamondbacks.
"Cole did a great job and the bullpen did a good job," Werth said. "We got Shane back and, hopefully, Jimmy will be back soon. Like last year, we have a team which has been through it. We're a confident team and we're going to keep pushing through like we did last season."