BackgroundWe aimed to evaluate the association of sedentary behavior (SB) and moderate to vigorous leisure-time physical activity (MVPA) with sleep quality during the COVID-19 pandemic.MethodsCross-sectional, population-based study in adults, conducted from October to December 2020 in the Iron Quadrangle region, Brazil. The outcome was sleep quality, evaluated with the Pittsburgh Sleep Quality Index. SB was assessed by self-report of total sitting time, before and during the pandemic. Individuals with ≥ 9 h of total sitting time were classified as SB. In addition, the ratio of time spent in MVPA to time in SB was analyzed. A contrasted directed acyclic graph (DAG) model was constructed to adjust logistic regression models.ResultsA total of 1629 individuals were evaluated, the prevalence of SB before the pandemic was 11.3% (95%CI: 8.6–14.8), and during the pandemic 15.2% (95%CI: 12.1–18.9). In multivariate analysis, the chance of poor sleep quality was 77% higher in subjects with SB ≥ 9 h per day (OR: 1.77; 95% CI: 1.02–2.97). Furthermore, a one-hour increase in SB during the pandemic, increased the chance of poor sleep quality by 8% (OR: 1.08; 95%CI 1.01–1.15). In the analysis of the ratio of MVPA per SB in individuals with SB ≥ 9 h, practicing 1 min of MVPA per hour of SB reduces the chance of poor sleep quality by 19% (OR: 0.84; 95%CI: 0.73–0.98).ConclusionSB during the pandemic was a factor associated with poor sleep quality, and the practice of MVPA can reduce the effects of SB.Graphical AbstractSupplementary InformationThe online version contains supplementary material available at 10.1186/s12889-023-16041-8.