The first chance of the game fell to the visitors with Jad Hakiki’s effort from just inside the area flashing over the bar.
Tiernan Lynch’s side grew into the game as the first half progressed, Hayden Cann coming close with a shot from distance.
Before Danny Mullen slipped Adam O’Reilly through in the area, O’Reilly looked set to score, but had his effort comfortably gathered by Sam Sargent, keeping the sides deadlocked at the break.
Early in the second half, a long ball from Brian Maher was expertly taken down by Duffy who carried the ball 40 yards before having his effort saved at the near post.
On the hour mark, it felt like it was going to be one of those evenings for Derry City. Duffy again was central in rounding Sargent and with the angle narrowing, he squared to Mullen who looked set to slot home into the empty net, denied only by a miraculous intervention from a Sligo defender.
In the final 10 minutes, Duffy, Cameron Dummigan and Brandon Fleming all came close to opening the scoring.
The drama wouldn’t end there as Duffy headed home a cross from the right in the 94th minute to snatch all three points for his hometown club, marking the signing of a new contract midweek with a winning goal.