Glamorgan 283 and 201 for 3 (Khawaja 79*, Carlson 69*) lead Derbyshire 362 (Hughes 103, Critchley 54*, Slater 52, Salter 4-105) by 122 runs
Glamorgan will go into the final day at Swansea with a lead of 122, and if they are able to extend that lead to anything over 250, Derbyshire will not find batting last an easy proposition on a St Helen's pitch that is responding to spin.
Khawaja is nearing his second successive Championship century, while Carlson, who missed the last game and nearly all the Royal London Cup games because of university examinations, played with ease and assurance and is unbeaten on 69.
Derbyshire were dismissed in their first innings for 362, a lead of 79, but they lost the opportunity of a much bigger lead by losing their last five wickets for five runs in 29 deliveries.
Alex Hughes had earlier scored his first Championship century of the summer, before he was run out for 103 after Billy Godleman was lbw to Andrew Salter.
There then followed a stand of 92 between Gary Wilson and Matt Critchley, with both batsmen playing watchfully against the spinners, Salter and the 19-year-old debutant Prem Sisodiya.
There was no hint of a collapse when Wilson was run out, attempting a second run from an overthrow that ricocheted from the stumps, and Critchley's fifty passed largely unnoticed.
The Derbyshire allrounder scored only four more runs as the lower order succumbed to spin. Tony Palladino missed a straight ball from Sisodiya, and after Salter had dismissed Hamidullah Qadri and Duanne Olivier in quick succession, Sisodiya ended the innings by having Ravi Rampaul caught at slip, and ending with creditable figures of 3 for 54 from 21.5 overs of controlled spin.
Nick Selman and Jack Murphy shared a useful opening partnership of 44 in Glamorgan's second innings before Murphy was out to leg before to Qadri in the penultimate over before tea. Murphy appeared unhappy with the decision, as did Selman when, shortly after the interval, he suffered the same fate against Critchley.
When Owen Morgan was bowled by Qadri, Glamorgan had lost three wickets for four runs, but Khawaja soon made his intentions clear by striking Critchley out of the ground.
Carlson, small in stature, used his feet effectively and both reached fifty in quick time. Khawaja was the first to the target from 70 balls, with a six and nine fours, while his junior partner was eight balls quicker.
The hundred partnership came up in 21.2 overs, when Carlson struck Qadri to the cover boundary for his seventh four, Glamorgan had extended their lead to over 100 runs.