Leicestershire 249 (Scriven 53, Conners 5-51) and 405 for 7 (Ahmed 122, Evans 64, Hill 60) trail Derbyshire 568 for 9 dec (Godleman 158, Reece 116, Madsen 92, Ahmed 5-114) by 188 runs
The England Under-19 allrounder decorated the last day of the season at the Incora County Ground with a breathtaking 122 off 113 balls to provide a memorable finale to a miserable season for Division Two's bottom club.
Derbyshire probably sensed the chance of an early finish when Ben Aitchison struck in the fourth over of the morning. Sam Evans had driven the fast bowler square to the boundary but the next ball drew him into playing and Wayne Madsen held a low catch at second slip.
Leicestershire's top order had collapsed in the first innings but Ahmed joined Hill to provide another impressive demonstration of his talent.
After a frenetic start, Ahmed settled in to bat with controlled aggression, playing shots all around the wicket to reach a brilliant hundred. An upper-cut for six off Aitchison was one of the memorable shots in a maiden fifty which came off 60 balls and he needed only 39 more to reach three figures.
There were no signs of nerves as he waltzed down the pitch after lunch to deposit Leus du Plooy's left-arm spin over the long-off boundary and he dished out the same treatment to off-spinner Alex Thomson. Another six off Thomson took him to 99 and the next ball he drove through the covers for his 12th four to reach three figures in only his third first-class match.
Ahmed is now in the distinguished company of former England allrounder Phillip DeFreitas who was the last Leicestershire player to score a century and take five wickets in an innings in the same game, in 2003 against Sussex at Grace Road.
It was the first time it has been done in a first-class game between the two counties at Derby since Derbyshire's Garnet Lee made an unbeaten 107 and took 5 for 31 in 1928.
Ahmed drove Thomson for a fifth six but in the next over he skied a slog-sweep at du Plooy and Luis Reece ran in to take the catch at mid-on.
Hill had played a valuable supporting role but he fell to the second new ball when he tried to cut Aitchison and was caught at first slip.
Conners beat the bat numerous times before he struck twice in consecutive overs, having Scriven caught behind pulling before Swindells dabbed the fast bowler into the gloves of Brooke Guest. But the light was fading before rain swept in just after 4.30pm with Derbyshire finishing fifth in Division Two while Leicestershire end the season without a Championship victory.