The Rams went into the match needing a point to stay up and leave Sunderland in the bottom two.
Timi Max Elsnik put them ahead with a superb long-range strike on nine minutes but the match turned after Louie Sibley's 75th-minute dismissal.
Harvey Barnes equalised in the 87th minute and fired the hosts ahead in the first minute of stoppage time. Sam Hughes then hit the third.
But Derby finished safely in 10th after Sunderland lost 1-0 at Swansea City, while Leicester moved back into second place.
Leicester: 27 Apr v Aston Villa (H) PL Cup