The visitors were reduced to 10 men after only five minutes when Courtney Baker-Richardson was dismissed for a late challenge on James Meredith.
Millwall made the most of their numerical advantage to take the lead just after the hour, Murray Wallace nodding in after team-mate Jake Cooper had headed a corner back across the face of goal.
However, the game changed on a substitution, with visiting boss Graham Potter, who lost Leroy Fer to injury before the break, sending on Jefferson Montero shortly after his side fell behind.
The Ecuador international marked his 29th birthday with two assists, first creating the equaliser for Kyle Naughton, who dummied to avoid a sliding defender before firing a low shot beyond goalkeeper Ben Amos.
Montero was creator-in-chief for the winner as well, as his square pass was tapped home from close range by the supporting Oliver McBurnie, while both teams hit the woodwork during stoppage-time in a dramatic ending.