The Phils were up 4-1 when Hamels left after a rain delay of one hour, 18 minutes midway through the sixth inning.
"The rain killed anything he had going," teammate Jayson Werth said. "The momentum switched, and they were able to get back in the game. Pretty soon you look up and it's the 12th inning and time to make a move."
With the score 4-all, Jimmy Rollins led off the 12th with a single against Burke Badenhop (5-4), took second on a sacrifice and came home on Utley's single. Utley advanced on a groundout, and following an intentional walk, Werth singled home another run.
Brad Lidge, pitching for the first time in a week, struggled to earn his 19th save in 25 chances. He walked two and gave up a run on a wild pitch before Dan Uggla grounded into the final out with a runner at third at 12:34 a.m.
Asked to describe the game, Phils manager Charlie Manuel said: "Crazy. We stayed that long and we won. That was something."
Philadelphia's Chad Durbin allowed the first two batters to reach in the bottom of the ninth, then retired the next three to preserve a tie. Florida stranded 13 runners, including seven in innings seven through nine.
"It was a weird game," Marlins manager Fredi Gonzalez said. "We just couldn't get that big knock when we needed to."
Clay Condrey (5-2), activated from the disabled list before the game, allowed one hit in the 11th and got the win.
The Phillies, who have won 11 of their past 12 games, increased their lead in the NL East to six games over Florida and Atlanta. The Phils have won seven games in a row in Miami, including five this season.
"We're playing good," Werth said. "We should continue to play good baseball and turn it on here down the stretch. I don't think you've seen the best baseball we've played yet."
Philadelphia improved to 28-15 on the road, best in the majors.
Utley also hit a two-run shot in the first inning for his 21st homer. Werth and Pedro Feliz had RBI hits in the fourth.
Hamels allowed four hits and threw 52 of his 68 pitches for strikes but remained winless in five career starts in Miami.
"It would have been nice to get through six or seven innings," Hamels said. "Our bullpen has been great all year. Unfortunately it didn't happen tonight."
The Marlins tied it with two runs in the eighth. Hanley Ramirez led off with a single, advanced on a groundout and came home on Ronny Paulino's two-out single. Jeremy Hermida walked against J.C. Romero, and Durbin gave up an RBI single to pinch-hitter Wes Helms.
Durbin struck out Chris Coghlan with the bases loaded to end the inning.
Rollins doubled to start the game and scored on Utley's homer against Ricky Nolasco.
Nolasco pitched six innings and gave up seven hits, including four in a row in the fourth inning. Ryan Howard and Raul Ibanez singled, Werth hit an RBI single and Feliz doubled home a run for a 4-1 lead.
Coghlan hit the Marlins' first leadoff first-inning homer of the season. Pinch-hitter Ross Gload singled home a run in the seventh, and Paulino hit a two-out RBI single -- his third hit -- in the eighth.
"We battled tonight," Helms said. "We fought until the end, and that's all you can ask for."
The Phillies designated RHP Tyler Walker for assignment to make room for Condrey (left oblique strain) . ... Newly acquired Philadelphia RHP Pedro Martinez will throw a bullpen session Saturday in Miami, then report to Class A Clearwater. ... The Phillies' combined one-hitter Thursday was their first since Sept. 26, 1986, against Montreal. ... Uggla, who is 3 for 23 against Hamels, was held out of the starting lineup. ... The gametime temperature was 90 degrees.