Purpose: Hospitals suffered from a precipitous loss of medical service globally due to COVID-19. The tragedy paradoxically produced an opportunity to investigate the patterns of change in medical services and revenue in hospitals at different levels when faced with a natural shock. This study aims to examine the effects of the COVID-19 pandemic in the first half of 2020 on hospital operation in Shanghai. Methods: We obtained monthly characteristic and operational data of public hospitals (N=156) from January 1, 2018, to July 31, 2020, in Shanghai from the China Statistical Survey of Health Resources and Services Program. We constructed a set of difference-indifferences models to investigate the pandemic (from February 1 to March 31, 2020) and post-pandemic (from April 1 to July 31, 2020) effects on operational outcomes in hospitals of different levels, including outpatient and inpatient visits, outpatient and inpatient revenue, as well as the differential effects on local and nonlocal patients. Results: There were 46 tertiary hospitals and 110 non-tertiary hospitals involved in this study. Compared to a non-tertiary hospital during the COVID-19 pandemic, a tertiary hospital averagely experienced substantially more significant losses in outpatient visits (57.91 thousand, p < 0.01), inpatient visits (1.93 thousand, p < 0.01), outpatient revenue (18.88 million RMB, p < 0.01), and inpatient revenue (30.65 million RMB, p < 0.01) monthly. Compared to a non-tertiary hospital in the post-pandemic period, a tertiary hospital averagely lost more outpatient visits (18.02 thousand, p < 0.01) from all patients and inpatient visits (0.15 thousand, p < 0.01) from nonlocal patients, but was associated with higher inpatient revenue (2.24 million RMB, p < 0.01) from all patients and outpatient revenue (0.87 million RMB, p < 0.01) from nonlocal patients monthly. Conclusion: Medical service and revenue for public hospitals in Shanghai dropped precipitously during the COVID-19 pandemic, but mainly recovered after the pandemic. Compared to non-tertiary hospitals, medical services and revenue in tertiary hospitals experienced more substantial reduction during the pandemic but had a faster recovery that maintained longer during the post-pandemic period.