After a relatively quiet first 40 minutes, Lee Gregory opened the scoring in what looks to be his final game in SE16 with a perfectly executed volley after being set up by Steve Morison.
Neil Harris' men had the chance to put the game to bed when the pair combined again and the Lions' goalscorer was clipped by visiting goalkeeper Max O'Leary for a penalty.
However, Shaun Williams' resulting spot-kick was saved and Lee Johnson's charges responded in clinical fashion, with Jamie Paterson and Diedhiou turning the contest on its head.
Bristol City were fifth and four points clear of seventh after a 3-2 win over West Bromwich Albion three weeks ago.
However, subsequent defeats to fellow promotion hopefuls Aston Villa and Derby, as well as a loss and a draw to Sheffield Wednesday and Reading respectively, meant that only a win would realistically keep the dream alive.
The West Country outfit had the lion's share of the chances in the opening period, but the hosts unexpectedly took the lead with five minutes of the first half to play.
There did not look much on when the ball was hoisted towards Morison on the edge of the box but the veteran managed to knock the ball down for Gregory, who flicked the ball up cleverly before hooking it outrageously over his shoulder and past the startled O'Leary into the bottom right corner.
Paterson then sent a sighter just wide, before O'Leary denied Gregory following a cute through-ball from Morison.
The first period certainly finished eventfully and Millwall had their tails up, with Jake Cooper hitting the post and Ryan Tunnicliffe seeing his effort booted away by O'Leary following good hold-up play from Gregory.
However, the 22-year-old stopper threatened to become the villain of the piece when he upended Gregory after the Sheffield-born forward attempted to latch onto another flick-on by Morison.
He made amends, though, with a sharp save to his right from Williams' weak effort and this sparked City into life.
With around 15 minutes to go, a foul on Matty Taylor gave Paterson the chance to level the scores and the winger did not disappoint, whipping the ball superbly inside the left-hand post to spark delirious scenes in the away end.
The noise was then ratcheted up a notch just five minutes later when Paterson turned provider, scampering through the middle before feeding Diedhiou who fired emphatically past Martin.
Millwall went in search of an equaliser, but were not able to find the inspiration required.
Lee Johnson's men will now hope Derby drop points at Swansea on Wednesday, which would leave them still in with a shout of reaching the Premier League when they travel to Hull on Sunday.