Keaton Jennings (82) and Jack Burnham (52) put on 123 after Durham slipped to 47-2 on the final morning at Southport.
Lancashire fought back through Tom Smith (5-25) as Durham lost five wickets for 25 runs to slump to 195-7.
Ben Stokes was run out for 36 on the brink of victory but Adam Hickey and Chris Rushworth guided Durham home.
Jennings and Burnham's third-wicket stand helped the visitors recover from the losses of Mark Stoneman, trapped lbw by Kyle Jarvis in the first over of the day, and Scott Borthwick before lunch.
But both fell in the space of five balls to spark a mini-collapse, as seamer Smith removed Michael Richardson, Paul Collingwood and Paul Coughlin before tea.
England all-rounder Stokes hit two sixes in one Simon Kerrigan over but was run out next ball with only four runs required.
Rushworth found the cover boundary to wrap up a hard-fought win and move Durham up to second in the Division One table, 13 points behind leaders Middlesex with a game in hand.
Lancashire boss Ashley Giles told BBC Radio Manchester:
"It's been a great spectacle for everyone who's come to watch at Southport, but disappointing for us to be on the wrong side of it and so close.
"To give up an 87-run lead first innings and bat as we did, led by Luke Procter, and then fight back this afternoon was great.
"The pitch didn't deteriorate quite as much as we thought it might, but there was always a ball in it. You felt when you were batting that there were times when it went flat but then times when wickets fell in clumps.".
Durham's Adam Hickey told BBC Radio Newcastle:
"Amazing really, especially after the first-innings disappointment when I found out why Jimmy Anderson is the best bowler in the world.
"It was really good to contribute. I came into this game wanting to do something for the lads, take wickets or get a score of some sort.
"We had a good 10 minutes before tea. That little period when me and Ben Stokes calmed it down swung it in our favour. But Tom Smith's spell made it the game it was."
Durham chased 247 to beat Lancashire by two wickets in a thrilling finish and maintain their County Championship title hopes.