Leicestershire 249 (Scriven 53, Conners 5-51) and 131 for 2 (Evans 59*) trail Derbyshire 568 for 9 dec (Godleman 158, Reece 116, Madsen 92, Ahmed 5-114) by 188 runs
The opener stood firm to give his side a chance of saving the game after Derbyshire declared on 568 for 9, their highest score against Leicestershire, and a lead of 319.
There was ice on the outfield early in the morning but the game started in glorious early autumn sunshine although the prospects for Leicestershire were less bright.
Madsen and Leus du Plooy accelerated against some indifferent bowling with the exception of Ahmed who induced a few false strokes and exerted a measure of control.
The-18-year-old removed du Plooy who drove back a return catch but Derbyshire's lead had increased to 219 by lunch with Madsen eying yet another century.
He was eight short when he tried to cut the 147th ball he faced and was caught behind off Walker but, if he does not bat again this season, he has scored 1800 runs in all formats.
Ahmed bagged two more wickets as the lower order hit out ahead of the declaration with Ben Aitchison caught at long off and Nick Potts bowled charging the leg-spinner after Chris Wright uprooted Alex Thomson's middle stump with a swinging yorker.
Faced with scoring 319 runs to make Derbyshire bat again, Leicestershire's first task was to negotiate 10 overs before tea which they managed assisted by bowling that was too short.
Derbyshire's attack adjusted their lines after the interval and made the first breakthrough in the second over of the evening session when Sol Budinger tried to pull Anuj Dal and got a steepling top edge to mid on.
It was hardly the shot the situation demanded but Evans and Louis Kimber displayed better judgement to add another 54 runs in 14 overs before another rash stroke ended the stand.
The introduction of Luis Reece's medium pace from the City End tempted Kimber into a pull at his third ball and Sam Conners took the catch just inside the rope at deep midwicket. But Evans and Lewis Hill dug in for 11 overs to leave Derbyshire with work to do on the final day.