Chris Mochrie came back to haunt Dunfermline with a late winner as Dundee United stretched their lead at the top of the Scottish Championship.
The game burst to life shortly before half-time as Kai Fotheringham pounced on the rebound to head his seventh goal of the season when Deniz Mehmet could only parry Liam Grimshaw's strike.
United - held by Inverness last weekend - were heading for more dropped points after Owen Moffat ran from halfway and capitalised on Declan Gallagher's slip to slot the equaliser.
But Mochrie, who spent last season on loan at Dunfermline, delivered the decisive moment.
The midfielder swivelled and lashed a shot past fellow substitute Harrison Sharp, who had replaced the injured Mehmet at half-time.
Sharp ought to have done better but United's momentum had been building, with Louis Moult twice denied and Glenn Middleton drilling narrowly wide.
The dramatic win moves United - still unbeaten in the league this season - seven points clear of second-place Raith Rovers, albeit having played two games more.
Dunfermline remain in the top four on goal difference but have now suffered four defeats in five.
Dundee United boss Jim Goodwin: "Delighted with the team and the performance. Not accepting the point away from home, pushing right to the end and getting maximum points.
"Chris Mochrie's got that in his locker. He's a really good young talent for us. It's good that the two substitutes combined and got the points for us."