COVID-19 pandemic continues to be a global health crisis. The gut microbiome critically affects the immune system, and some respiratory infections are associated with changes in the gut microbiome; here, we evaluated the role of nutritional and lifestyle habits that modulate gut microbiota on COVID-19 outcomes in a longitudinal cohort study that included 200 patients infected with COVID-19. Of these, 122 cases were mild and seventy-eight were moderate, according to WHO classification. After detailed explanation by a consultant in clinical nutrition, participants responded to a written questionnaire on daily sugar, prebiotic intake in food, sleeping hours, exercise duration and antibiotic prescription, during the past 1 year before infection. Daily consumption of prebiotic-containing foods, less sugar, regular exercise, adequate sleep and fewer antibiotic prescriptions led to a milder disease and rapid virus clearance. Additionally, data on these factors were compiled into a single score, the ESSAP score (Exercise, Sugar consumption, Sleeping hours, Antibiotics taken, and Prebiotics consumption; 0–11 points), median ESSAP score was 5 for both mild and moderate cases; however, the range was 4–8 in mild cases, but 1–6 in moderate (P = 0·001, OR: 4·2, 95 % CI 1·9, 9·1); our results showed a negative correlation between regular consumption of yogurt containing probiotics and disease severity (P = 0·007, OR: 1·6, 95 % CI 1·1, 2·1). Mild COVID-19 disease was associated with 10–20 min of daily exercise (P = 0·016), sleeping at least 8 h daily, prescribed antibiotics less than 5 times per year (P = 0·077) and ate plenty of prebiotic-containing food.