The hosts led when Ben Richards-Everton volleyed home but Jordan Hugill slotted in to equalise for the visitors.
With four minutes of extra time left, Jordan Clark restored the lead but Hugill levelled again in added time.
But Billy Kee struck in the third minute of stoppage time to give Stanley victory over their Lancashire rivals.
Kee also scored in Accrington's 3-1 win against Colchester on the opening day of League Two.
They have now knocked out higher league opposition in the EFL Cup for the second successive year after they beat Burnley last season.
Accrington Stanley boss John Coleman told BBC Radio Lancashire:
"I'm delighted with the result as it was a difficult game. It was a full-blooded derby and just to be competing against teams like this on what we believe is a level playing field is testament to how far the club's come.
"Preston are a good side and they showed that. They moved the ball really well and we knew that from when we played them in a pre-season friendly.
"We were a different animal tonight. We created far more problems for them."
Preston North End manager Alex Neil told BBC Radio Lancashire:
"To be honest we shouldn't have been forcing for extra-time. At 1-1 we looked like we were going to go on and win the game.
"When we conceded the corner I thought I've seen this a million times before. We conceded from a set piece which is really frustrating.
"If you look at the game, we had numerous opportunities and chances, we didn't take them or make them count and ultimately we got punished because of that."
Match ends, Accrington Stanley 3, Preston North End 2.
Second Half ends, Accrington Stanley 3, Preston North End 2.
Attempt missed. Daryl Horgan (Preston North End) right footed shot from the centre of the box misses to the right.
Attempt blocked. Paul Gallagher (Preston North End) right footed shot from the centre of the box is blocked.
Corner,  Preston North End. Conceded by Tyler Hornby-Forbes.
Goal!  Accrington Stanley 3, Preston North End 2. Billy Kee (Accrington Stanley) header from very close range to the high centre of the goal. Assisted by Tom Dallison following a corner.
Corner,  Accrington Stanley. Conceded by Daniel Johnson.
Goal!  Accrington Stanley 2, Preston North End 2. Jordan Hugill (Preston North End) header from the left side of the six yard box to the bottom right corner. Assisted by Sean Maguire.
Corner,  Accrington Stanley. Conceded by Andrew Boyle.
Goal!  Accrington Stanley 2, Preston North End 1. Jordan Clark (Accrington Stanley) right footed shot from the centre of the box to the bottom right corner. Assisted by Kayden Jackson.
Corner,  Accrington Stanley. Conceded by Chris Maxwell.
Attempt saved. Liam Nolan (Accrington Stanley) right footed shot from outside the box is saved in the bottom left corner.
Attempt missed. Billy Kee (Accrington Stanley) right footed shot from outside the box is high and wide to the right.
Substitution, Accrington Stanley. Seamus Conneely replaces Scott Brown.
Kayden Jackson (Accrington Stanley) wins a free kick in the defensive half.
Foul by Alan Browne (Preston North End).
Substitution, Preston North End. Alan Browne replaces Callum Robinson.
Corner,  Preston North End. Conceded by Scott Brown.
Attempt saved. Kevin O'Connor (Preston North End) header from the centre of the box is saved in the centre of the goal.
Corner,  Preston North End. Conceded by Ben Richards-Everton.
Foul by Jordan Clark (Accrington Stanley).
Kevin O'Connor (Preston North End) wins a free kick in the defensive half.
Corner,  Accrington Stanley. Conceded by Paul Gallagher.
Attempt missed. Kevin O'Connor (Preston North End) right footed shot from outside the box is high and wide to the right.
Ben Richards-Everton (Accrington Stanley) wins a free kick in the attacking half.
Foul by Jordan Hugill (Preston North End).
Attempt blocked. Sean McConville (Accrington Stanley) right footed shot from the left side of the box is blocked.
Goal!  Accrington Stanley 1, Preston North End 1. Jordan Hugill (Preston North End) right footed shot from the right side of the box to the bottom left corner. Assisted by Daryl Horgan following a fast break.
Attempt blocked. Jordan Clark (Accrington Stanley) right footed shot from the right side of the box is blocked.
Foul by Billy Kee (Accrington Stanley).
Andrew Boyle (Preston North End) wins a free kick on the left wing.
Attempt blocked. Paul Gallagher (Preston North End) right footed shot from outside the box is blocked.
Attempt saved. Jordan Hugill (Preston North End) right footed shot from outside the box is saved in the bottom right corner.
Substitution, Preston North End. Sean Maguire replaces Liam Grimshaw.
Ben Richards-Everton (Accrington Stanley) wins a free kick in the attacking half.
Foul by Jordan Hugill (Preston North End).
Attempt blocked. Kayden Jackson (Accrington Stanley) right footed shot from outside the box is blocked.
Corner,  Preston North End. Conceded by Mark Hughes.
Attempt missed. Daniel Johnson (Preston North End) right footed shot from outside the box misses to the left.
Attempt saved. Callum Robinson (Preston North End) right footed shot from outside the box is saved in the bottom right corner.
Accrington Stanley secured a dramatic late victory over Championship side Preston North End to seal their place in the second round of the EFL Cup.