Thea Brookes (30 not out) and Paige Scholfield (38) shared a 69-run eighth-wicket partnership to leave the hosts needing eight runs from the final over.
However, Hayley Matthews bowled Rebecca Grundy and then Beth Langston was caught, with Lightning all out for 158.
Thunder had posted an imposing 164-8 after Amy Satterthwaite's half-century and Deandra Dottin's quickfire 42.
A close run chase from Lightning had looked unlikely when captain Georgia Elwiss (20) was run out at the non-striker's end and the hosts slipped to 57-4.
England spinner Sophie Ecclestone's 3-23 then reduced Loughborough to 88-7 but Brookes and Scholfield looked to counter-attack - striking eight fours and a six as they brought up their fifty partnership from only 28 balls.
Despite Scholfield being reprieved on 36 when she was dropped by Nat Brown, she was bowled by Dottin off the next ball as the enthralling game swung one final time in Lancashire's favour.
Both sides now have one victory and one defeat after their first two matches, but Lightning remain above Thunder thanks to their bonus-point win in the league's inaugural match on 30 July.
Lancashire Thunder edged to a nail-biting six-run victory over Loughborough Lightning at Haslegrave.