Derbyshire 307 (Hosein 83*, A Hughes 55, Shreck 4-78) and 286 for 8 (Madsen 134*, Hosein 58) lead Leicestershire 247 (Cosgrove 95*, Davis 4-68) by 346 runs
Wayne Madsen's 23rd first-class century for Derbyshire has given his team an excellent chance of ending their county championship drought in the Division Two match against Leicestershire at Derby.
Derbyshire were in trouble at 57 for 5, a lead of only 117, but Madsen and wicketkeeper Harvey Hosein, 58, added 143 in 42 overs to put the home side on course for a first four day win of the season.
Leicestershire skipper Mark Cosgrove had made an unbeaten 95 and Clint McKay claimed his 50th championship wicket of the summer but Madsen's unbeaten 134 guided Derbyshire to 286 for 8 at the close, a lead of 346.
Cosgrove had two aims when play started, to get to three figures and to restrict Derbyshire's lead, but Leicestershire added only 19 runs in an hour for the last two wickets.
Tom Milnes found some away swing to take the outside edge of Richard Jones's bat and although Charlie Shreck stayed with Cosgrove for nearly nine overs, Tony Palladino had him caught at third slip off his first ball of the day.
Cosgrove deserved a hundred for the way he had battled with a damaged hand to keep his side in the game but his bowlers hit back strongly either side of lunch to regain the initiative.
Ben Slater had already survived a confident appeal for a catch behind before he clipped Clint McKay low to midwicket and Derbyshire captain Billy Godleman quickly followed when he played on to a ball that kept a little low.
Signs of uneven bounce were both good and bad news for Leicestershire but their hopes of chasing a modest target in the fourth innings rose when Alex Hughes was run out by a direct hit after Madsen called him through for a sharp single.
When Neil Broom was lbw for three to one that nipped back from Neil Dexter fourth ball after lunch, Derbyshire were 32 for 4 and in danger of letting the game slip away but although Tom Wood fell to Shreck nine overs later, it was the signal for the game to take another twist.
Perhaps the run-out of Hughes had provided Madsen with added motivation or maybe it was because he was batting against Leicestershire who must be fed up of bowling at him.
He has now scored four centuries against them and this latest one was his fifth of the season and his fourth in the last nine championship matches. Hosein completed his second fifty of the match and Tom Milnes and Tony Palladino helped take the lead well past 300 but the day belonged to Madsen.