The diagnostic delay of tuberculosis (TB) contributes to further transmission and impedes the implementation of the End TB Strategy. Therefore, we aimed to describe the characteristics of patient delay, health system delay, and total delay among TB patients in Shanghai, identify areas at high risk for delay, and explore the potential factors of long delay at individual and spatial levels. The study included TB patients among migrants and residents in Shanghai between January 2010 and December 2018. Patient and health system delays exceeding 14 days and total delays exceeding 28 days were defined as long delays. Time trends of long delays were evaluated by Joinpoint regression. Multivariable logistic regression analysis was employed to analyze influencing factors of long delays. Spatial analysis of delays was conducted using ArcGIS, and the hierarchical Bayesian spatial model was utilized to explore associated spatial factors. Overall, 61,050 TB patients were notified during the study period. Median patient, health system, and total delays were 12 days (IQR: 3-26), 9 days (IQR: 4-18), and 27 days (IQR: 15-43), respectively. Migrants, females, older adults, symptomatic visits to TB-designated facilities, and pathogen-positive were associated with longer patient delays, while pathogen-negative, active case findings and symptomatic visits to non-TB-designated facilities were associated with long health system delays (LHD). Spatial analysis revealed Chongming Island was a hotspot for patient delay, while western areas of Shanghai, with a high proportion of internal migrants and industrial parks, were at high risk for LHD. The application of rapid molecular diagnostic methods was associated with reduced health system delays. Despite a relatively shorter diagnostic delay of TB than in the other regions in China, there was vital social-demographic and spatial heterogeneity in the occurrence of long delays in Shanghai. While the active case finding and rapid molecular diagnosis reduced the delay, novel targeted interventions are still required to address the challenges of TB diagnosis among both migrants and residents in this urban setting.