BACKGROUND: Cognitive function was significantly associated with post-stroke depression and anxiety in stroke patients. However, no studies have examined whether there is an interaction. this study purposed to investigate whether cognitive function mediates the effect of enrollment in post-acute care (PAC) programs on depression or anxiety in stroke patients and whether the indicators are moderated in the pathway. METHODS: This is a prospective observational cohort study. A group of patients who had received PAC for stroke at one of two medical centers (PAC group, n = 2,087) was compared with a group who had received standard care for stroke at one of four hospitals (three regional hospitals and one district hospital; non-PAC group, n = 1,591) in Taiwan from March, 2015, to March, 2022. The effects of PAC on cognitive function and depression and anxiety at baseline, 12th week, and 1st year after rehabilitation were investigated using structural equation modeling (SEM). The effect of each variable on the moderation of different pathways in the model was analyzed using AMOS 23.0, and The SPSS PROCESS macro also was used to perform mediation analysis. RESULTS: The PAC program had a mediating effect on cognition and depression at week 12 (a*b= -0.098, P<0.05) on cognition and anxiety at week 12 (a*b= -0.107, P<0.05), and the PAC program had a direct effect on depression and anxiety in the first year. It was found that acute lengths of stay had a significant moderation effect in the model (X*W→M=0.204, P=0.002), but the model lost its mediating effect when the moderation variable was added. CONCLUSIONS: Patients with stroke should receive post-acute care as soon as possible to improve their cognitive function after rehabilitation, to maximize the effectiveness of treatment for mental disorders, and to reduce the burden of the disease.