question: This study aimed to investigate the effects of long-term home quarantine on the mental health of people during the COVID-19 epidemic in Shanghai. We conducted an online questionnaire survey on March 26 2020 and collected data on demographics, level of physical activity (PA), and mental health status of the participants. We assessed the mental health status using the Patient Health Questionnaire (PHQ-9) and Generalized Anxiety Disorder Scale (GAD-7), whereas PA was assessed using International Physical Activity Questionnaire Short Form (IPAQ-SF). Of all 2,409 valid samples, participants reported performing a total of 2015.20 metabolic equivalent of task (MET)-minutes/week of total PA before the outbreak period and 1720.29 MET-minutes/week of total PA during the outbreak period (p < 0.001). Participants who spent a longer time at home reported to have a better performance on the PHQ-9 (p = 0.087) and GAD-7 (p < 0.001). A high level of PA was considered an protective factor against depression (OR = 0.755, 95% CI 0.603–0.944, p < 0.001). Additionally, a high level of PA had a preventative effect on anxiety (OR = 0.741, 95% CI 0.568–0.967, p < 0.001), and a longer working period during the outbreak was shown to be a risk factor for anxiety (11–29 days, OR 1.455, 95% CI 1.110–1.909; 30–60 days OR 1.619, 95% CI 1.227–2.316). Home confinement during the pandemic might not have a negative effect on mental health provided that people engage in more PA indoors. This study encourages interventions for mental health problems through physical exercise.