Determining the relationship between air quality and economic development can help develop effective strategies for environmental sustainability. However, such analyses have scarcely been performed due to a lack of reliable methods, especially at the urban scale. Shenzhen, an epitome of China's reform and opening-up, has experienced rapid urbanization from a fishing village to a megacity in only 40 years. Here, we observed great historical changes in air quality that deteriorated first and then improved in Shenzhen and successfully quantified key socioeconomic drivers of the reduction in PM2.5 in the last ten years using a macrolevel economic decomposition model, which was strongly supported by microlevel evidence from source apportionment modelling based on the long-term PM2.5 component observation. We found that the benefits from energy and industrial structure adjustments were not necessarily enough to offset the adverse effects of rapid urban economic growth, while proactive and powerful emission control of extensive pollution sources, especially those for gaseous precursors of secondary PM2.5 components (e.g., SO2 and VOCs), was indispensable to drive the continuous decline in PM2.5. The success in retrieving blue sky in Shenzhen provides unique insights for the sustainable development of global megacities.