Cognitively challenging training sessions during robot-assisted gait training after stroke were shown to be key requirements for the success of rehabilitation. Despite a broad variability of cognitive impairments amongst the stroke population, current rehabilitation environments do not adapt to the cognitive capabilities of the patient, as cognitive load cannot be objectively assessed in real-time. We provided healthy subjects and stroke patients with a virtual task during robot-assisted gait training, which allowed modulating cognitive load by adapting the difficulty level of the task. We quantified the cognitive load of stroke patients by using psychophysiological measurements and performance data. In open-loop experiments with healthy subjects and stroke patients, we obtained training data for a linear, adaptive classifier that estimated the current cognitive load of patients in real-time. We verified our classification results via questionnaires and obtained 88% correct classification in healthy subjects and 75% in patients. Using the pre-trained, adaptive classifier, we closed the cognitive control loop around healthy subjects and stroke patients by automatically adapting the difficulty level of the virtual task in real-time such that patients were neither cognitively overloaded nor under-challenged.