BackgroundMedical students have higher risk of psychological disorders due to the relatively stressful environment. Educators are becoming increasingly aware of the impact of stresses on the students general well-being. The objective of the current study was to examine the prevalence of and risk factors for depressive and anxiety symptoms among first-year and fifth-year medical students. Additionally, we aimed to determine whether the COVID-19 pandemic has affected students’ mental well-being.MethodsA cross-sectional study was performed at the College of Medicine at King Saud University between September 2020 and January 2021. The target population was first-year and fifth-year medical students. Depressive symptoms were screened using the 9-item Patient Health Questionnaire (PHQ-9), while anxiety symptoms were screened using the 7-item Generalized Anxiety Disorder assessment (GAD-7). Students were also directly asked about the effect of the COVID-19 pandemic on their mental well-being. Outcomes were compared between groups using the chi-squared test and Student’s t test. Multivariate logistic regression analysis was performed to identify factors associated with depressive and anxiety symptoms.ResultsA total of 182 medical students were included. Depressive symptoms (52.9% versus 35.8%,p= 0.020) and anxiety symptoms (35.6% versus 26.3%,p= 0.176) were higher in the first-year students than in the fifth-year students. Approximately 19.2% of the students were worried about acquiring COVID-19, 49.4% were worried about academic performance, and 30.8% were feeling sad, depressed or anxious during the COVID-19 pandemic. Independent risk factors for depressive symptoms included having concomitant anxiety, being worried about acquiring COVID-19, being worried about academic performance, and feeling sad, depressed or anxious. Independent risk factors for anxiety included having a lower grade point average and having concomitant depressive symptoms.ConclusionMedical students have an alarmingly high prevalence of depressive and anxiety symptoms, which might have been negatively impacted by the COVID-19 pandemic. There is a need for a special mental health program targeting new and current medical students.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12909-023-04387-x.