Derbyshire 130 (Dal 55, Pennington 4-36) and 286 for 6 (Dal 85*, Madsen 69, McKiernan 58*) lead Worcestershire 185 (Kashif 52, Aitchison 4-40) by 231 runs
Madsen reached four figures in a campaign for the sixth time when he reached 32 and went onto make an invaluable 69.
The 38-year-old had scored six Championship centuries in 2016 but had taken the next five seasons to double that tally as his impact slowly declined in red-ball cricket in recent years.
He has now surpassed 700 Championship runs this summer in the number seven role after ending unbeaten on 85 in addition to chipping in with 22 wickets.
Gareth Roderick was undone by a delivery of extra bounce which he edged through to keeper Brooke Guest, Joe Leach (0) was lbw working to leg and Josh Baker (2) pushed forward and was bowled.
Ed Barnard again looked in good form and when on 13 surpassed his previous best first-class run tally in a season of 746 achieved last summer.
But after making 39 he presented Guest his sixth catch of the innings when nicking an away swinger from Dal.
It was the first time a Derbyshire keeper had taken six or more dismissals in an innings since Harvey Hosein against Surrey at The Oval in 2014.
The sun had come out by the time Derbyshire launched their second innings but ball initially continued to dominate over bat.
Leach made good use of the new ball either side of lunch as Luis Reece went back to a good length ball and was lbw and then Guest was bowled via an inside edge.
Opener Harry Came looked in good touch as Derbyshire wiped out their first-innings arrears with still eight wickets in hand.
But the return to the attack of Dillon Pennington dealt a double blow to the Peakites.
Came, on 39, went lbw to a delivery which arrowed back in and then Derbyshire captain, Leus du Plooy was bowled after working to leg.
Derbyshire were only 37 ahead when they lost a fifth wicket as Hilton Cartwright was stumped in bizarre fashion.
He failed to connect with a legside hit aimed at spinner Josh Baker and was stumped as the ball rebounded off the pads of keeper Gareth Roderick onto the stumps.
Madsen swept Baker for four to complete 1,000 first class runs for the season before going lbw to a ball that nipped back in from Barnard.
But Dal and McKiernan swung the game in Derbyshire’s favour with a 100 partnership from just 121 balls as batting looked increasingly straightforward.