Wanderers produced a stunning fightback with three goals in 20 pulsating second-half minutes to get their top-six push back in top gear.
The Whites were staring at the possibility of a third successive away defeat to a side in the bottom half of the League One table when they went 2-0 down just after half-time.
But in a tremendous show of character from Ian Evatt’s men – and a tactical shift from the manager – they forced a Harvey Rodgers’ own-goal to kick-start a comeback.
Kieran Lee then equalised with just under 20 minutes to go.
And then in front of the joyous travelling fans – who made up more than half the Wham Stadium gate – Dapo Afolayan scored a superbly-taken winner to cap an outstanding performance.
The win, the Whites’ first in four league games with the first goals in that dry run, lifted them back up to sixth place and with back-to-back home games to come, could prove a pivotal point in the campaign.
With Conor Bradley suspended, Lloyd Isgrove made a first league start in close to 11 months following his impressive return in the mid-week Papa Johns Trophy win over Leeds United.
Kyle Dempsey and Lee were also back to start a league game as Wanderers looked to respond to remedy their away-day issues and reclaim a place in the play-off zone.
But Stanley also had a point to prove following successive 3-0 league defeats and the Reds were rewarded for a positive start with the opening goal after just eight minutes.
Former Wanderers’ midfielder Joe Pritchard had already forced James Trafford into early action when he broke clear to square the ball for midfielder Shaun Walley to roll home his first goal since returning to the club in the summer.
The goal had Wanderers on the back foot and Harvey Rodgers then worked ex-Stanley loanee Trafford with a long-range effort.
But with Dempsey driving Wanderers forward from midfield and Charles striving to make a mark against his former club, the visitors gradually gained a measure of control as they looked for an equaliser.
Wanderers forced a succession of corners and probed to find an opening inside the Stanley penalty area.
But the nearest they came to levelling the scores by the break came just before half-time when Isgrove found Dempsey for a shot which had Toby Savin at full stretch to save, Mitch Clark reacting smartly to clear the rebound as Charles waited to pounce.
The momentum had looked to be swinging Wanderers’ way but within minutes of the re-start they had conceded again to make their task even harder.
The Reds again came swiftly out of the blocks and after Trafford had saved from Whalley, a long throw from Doug Thame caused chaos in the Whites’ penalty area and bounced into his own net off defender George Johnston.
It could have got worse as Ethan Hamilton was denied a third by Ricardo Almeida Santos’ goalline clearance.
But Wanderers hung on and then delivered the response they needed.
Jon Dadi Bodvarsson headed an Isgrove cross just over the bar before both made way as part of a triple substitution.
And one of those introduced via the bench played a part in the goal that got Wanderers back in the contest.
Jack Iredale – on at left back in a switch to a flat back four – delivered the free-kick which allowed Johnston to make amends with a header across goal which struck Rodgers last to level up the own-goals.
Suddenly Wanderers had renewed belief as they stepped up the tempo and looked a threat every time they went forward.
Afolayan – with a new lease of life in a more advanced role – and Lee were both denied by Savin, who then made a superb save to keep out another Johnston header.
But even the inspired Stanley keeper was unable to prevent the Whites making it 2-2 with 20 minutes to go.
Afolayan was inevitably involved again and when his shot was deflected up into the air, Elias Kachunga kept the ball alive and allowed Lee to time his arrival perfectly to tap in his second goal of the season.
The Wanderers’ fans behind that goal were ecstatic and two minutes later were celebrating again when the dramatic fightback was complete.
Charles had just struck an effort into the side netting with one opening when Afolayan, who was becoming close to unplayable, again sliced through the Reds’ defence to steer home a perfect finish to claim his third goal of the campaign.
It was electric stuff and Afolayan almost added a fourth with another burst into the box.
But with Wanderers negotiating seven minutes of added time, he had done enough to seal a thrilling win on a remarkable afternoon.
Wanderers: Trafford; Jones, Santos, Johnston; Isgrove (Iredale 53), Williams (Thomason 53), Dempsey, Afolayan (Sadlier 90); Lee; Bodvarsson (Kachunga 53), Charles (Bakayoko 87). Substitutes: Sheehan, Morley.
Booked: Jones.
Accrington Stanley: Savin; Clark, Tharme, Astley, Rodgers; Whalley (Delfouneso 85), Coyle, Hamilton, McConville (Longelo 78); Pritchard; Leigh. Substitutes: Jensen, Nolan, Martin, Sisay, Fernandes.
Booked: Clark, McConville, Whalley
Referee: Robert Madden
Attendance: 4,829 (2,615 Wanderers)