Birmingham-born Martin went with a kilometre to go on the final climb and held off the late challenge of Pierre Roger Latour by a second.
Martin came home second the last time a Tour stage ended in Mur de Bretagne three years ago and he admitted he had been obsessed about winning here this time on a punchy climb that suited his abilities.
While his team once again showed cracks when finishing 15th of 22 squads in the stage three team time trial in Cholet last Monday, Martin's victory yesterday sees him move into 21st place overall, a minute and 27 seconds behind current race leader Greg Van Avermaet of BMC.
AG2R's Romain Bardet cracked in the heat of the final ascent and lost 31secs, while fellow contender Tom Dumoulin (Sunweb), the 2017 Giro d'Italia champion, lost almost a minute after suffering a mechanical problem.
"My first thoughts are that I hope my wife hasn't gone into labour", smiled Martin as he caught his breath.
How hero doctor's Aussie accent played surprise role in Thai cave rescue
Without him "this mission may not have succeeded", the Thai rescue chief, Narongsak Osottanakorn, told reporters late Wednesday. The team's morale was hit when a former Thai Navy SEAL, Samarn Kunan, 38, died while helping lay out oxygen tanks underground.
BMC rider Porte, Italian Vincenzo Nibali and Britain's Geraint Thomas all crossed the line three seconds off the pace after the 181-kilometre ride from Brest to Mur de Bretagne, with defending champion Chris Froome five seconds further back.
Dumoulin and his Sunweb team compounded the mechanical mishap by getting a 20-second penalty when Dumoulin stayed too close to the team vehicle while trying to catch the pack, thereby benefiting from its draft that pulled him along. "Unfortunately I couldn't get a podium there, as I'd have had enough seconds to get the jersey". I had really good legs and when I went my legs kept coming and coming, " Martin said.
Joining Porte in those time gains was Irish stage victor Daniel Martin (UAE), Spaniards Alejandro Valverde (Movistar) and Mikel Landa (Movistar), Briton Adam Yates (Mitchelton-Scott), Welshman Geraint Thomas (Sky), Colombian Nairo Quintana (Movistar), Italian Vincenzo Nibali (Bahrain-Merida), and Dane Jacob Fuglsang (Astana).
Dumoulin, the time trial world champion and 2017 Giro d'Italia victor, was slowed by a tire puncture at the foot of the final ascent and lost 53 seconds.
Thomas picked up two bonus seconds during the stage, and left Froome in his wake on the final climb as he rode away from the reigning champion with a group of the other favourites.