Cain (5-2) won his fourth straight start, working around five hits and three walks to surrender a pair of runs while striking out four.
Sergio Romo fanned Omar Infante to snuff out a seventh-inning Miami rally and Santiago Casilla recorded the final four outs for his 12th save as the Giants salvaged a split in their four-game set at Marlins Park.
Melky Cabrera went 4-for-4 with an RBI and scored all three Giants runs while Buster Posey added a pair of hits, including an RBI double, in the victory.
Miami's Ricky Nolasco (5-3) was tagged with the loss, allowing three runs on five hits over seven innings.
Swim Week Miami Beach 2014 [PHOTOS]