A heat wave with temperatures over 35°C and sunny stagnant meteorological conditions occurred in Shanghai from 27 July to 5 August 2015, leading to a sustained episode of high ozone lasting 12 days. We have conducted a detailed source apportionment of surface ozone, by precursor source category and region, using a photochemical transport model. In this episode, a southwesterly wind prevailed over the Yangtze River Delta, and therefore precursors from the local Shanghai region and the region immediately to the south of Shanghai are the two major contributors (in total 90%) to ozone in Shanghai. The source apportionment reveals that local industrial sources and energy/biogenic sources in neighbouring regions are the principal causes for the high levels of ozone. By examining the contributions from individual physical and chemical processes, we show that ozone concentrations start to rise rapidly in the morning because chemical production dominates as the solar radiation increases, and while there is little removal by deposition when ozone remains low. In general, chemical production, horizontal advection and vertical diffusion contribute to increase ozone concentration during daytime, and deposition and vertical advection reduce ozone concentrations.