Brandon Lyon (0-1) came on for his first action in the 11th and promptly gave up the deciding run.
Coghlan reached on an infield hit to open the inning and Sanchez fouled off four consecutive pitches before sending the ball deep to left field.
Miami snapped a two-game skid and Houston lost its third in a row.
The Astros brought about extra innings thanks to a two-run homer in the eighth from J.D. Martinez.
Coghlan's hit made a winner out of Ryan Webb (1-0), who worked the top of the 11th.
Miami let an early 4-1 lead get away, but despite that the bullpen turned in an excellent performance. After starter Ricky Nolasco went five innings, six relievers pitched an inning each for the Marlins. Five of them did not allow a hit.
Megyn Kelly: Santa Claus and Jesus are both white men
Costly malfunction causes beer flood at Boston-area brewery