The Phils were up 4-1 when Hamels left after a rain delay of one hour, 18 minutes midway through the sixth inning. The bullpen blew the lead, then escaped several jams in the final innings.
Brad Lidge, pitching for the first time in a week, walked two in the 12th and gave up a run on a wild pitch but earned his 19th save in 25 chances. Dan Uggla grounded out with a runner at third to end the game.
With the score 4-all, Jimmy Rollins led off the 12th with a single off 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, Jayson Werth singled home another run.
The Phils' 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 seven runners in innings seven through nine.
Clay Condrey (5-2), activated from the disabled list before the game, allowed one hit in the 11th.
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.
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 because 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.