Background The duration of viral shedding is central to the guidance of decisions about isolation precautions and antiviral treatment. However, studies regarding the risk factors associated with prolonged shedding of the severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2) and the impact of lopinavir/ritonavir (LPV/r) treatment on viral shedding remain scarce. Methods Data were collected from all SARS-CoV-2 infected patients who were admitted to isolation wards and had reverse transcription PCR conversion at the No. 3 People's Hospital of Hubei province, China, between 31 January and 9 March 2020. We compared clinical characteristics and SARS-CoV-2 RNA shedding between patients initiated with LPV/r treatment and those without. Logistic regression analysis was employed to evaluate the risk factors associated with prolonged viral shedding. Results Of 120 patients, the median age was 52 years, 54 (45%) were male and 78 (65%) received LPV/r treatment. The median duration of SARS-CoV-2 RNA detection from symptom onset was 23 days (interquartile range 18–32 days). Older age (OR 1.03, 95% CI 1.00–1.05; p=0.03) and the lack of LPV/r treatment (OR 2.42, 95% CI 1.10–5.36; p=0.029) were independent risk factors for prolonged SARS-CoV-2 RNA shedding. Patients who initiated LPV/r treatment within 10 days from symptom onset, but not initiated from day 11 onwards, had significantly shorter viral shedding duration compared with those without LPV/r treatment (median 19 days versus 28.5 days; log-rank p<0.001). Conclusion Older age and the lack of LPV/r treatment were independently associated with prolonged SARS-CoV-2 RNA shedding in patients with coronavirus disease 2019 (COVID-19). Earlier administration of LPV/r treatment could shorten viral shedding duration.