BACKGROUND Symptoms of depression and comorbid anxiety are known risk factors for cognitive impairment in major depressive disorder (MDD). Understanding their relationships is crucial for developing targeted interventions to mitigate cognitive impairments in MDD patients. We expect that the severity of sleep disturbances and other depressive symptoms will be positively correlated with the degree of cognitive impairments. We also hypothesize that anxiety symptoms, especially psychic anxiety, is a key factor in predicting cognitive performance in MDD patients and may indirectly contribute to cognitive impairment by affecting sleep disturbances and other potential factors. AIM To determine which dimension of the depressive and anxiety symptoms predicts cognitive impairment during a depressive episode. METHODS A comprehensive neurocognitive test battery assessed executive function, attention, processing speed, and memory in 162 medication-free MDD patients and 142 matched healthy controls. The 24-item Hamilton Depression Rating Scale was used to assess depressive symptoms, and the 14-item Hamilton Anxiety Scale was used to assess anxiety symptoms. Linear regression analyses and mediation analyses were conducted to evaluate the impact of depressive and anxiety symptoms, as well as their interactions, on cognitive impairments. RESULTS Among the depressive symptoms, sleep disturbances were associated with poorer executive function (P = 0.004), lower processing speed (P = 0.047), and memory impairments (P < 0.001), and psychomotor retardation (PR) was associated with lower processing speed in patients with MDD (P = 0.019). Notably, PR was found to mediate the impact of sleep disturbances on the processing speed. Regarding anxiety symptoms, psychic anxiety, rather than somatic anxiety, was associated with cognitive impairments in all aspects. Sleep disturbances mediated the effect of psychic anxiety on executive function [β = -0.013, BC CI (-0.027, -0.001)] and memory [β = -0.149, BC CI (-0.237, -0.063)], while PR mediated its effect on processing speed (β = -0.023, BC CI (-0.045, -0.004)]. CONCLUSION Sleep disturbances may be a key predictor of poorer executive function, lower processing speed, and memory loss, while PR is crucial for lower processing speed during a depressive episode. Psychic anxiety contributes to all aspects of cognitive impairments, mediated by sleep disturbances and PR.