In November 1955, Cao was transferred to Shanghai and served as deputy secretary of the Shanghai Municipal Committee of the CCP. In December, the first Shanghai People's Congress unanimously elected him as deputy mayor of Shanghai. In July 1956, he was elected as Secretary of the Municipal Secretariat. In January 1957, he was appointed as the Executive Vice Mayor. In December 1965, he was elected as the third mayor of Shanghai with a unanimous vote by the People's Congress.[1]
At the start of the Cultural Revolution, Cao presided over the daily work of the Shanghai Municipal Party Committee due to Chen Pixian, then First Secretary of the Municipal Committee still recovering from his illness at the time of May 1966. In 1967, Cao was deposed and arrested alongside the rest of the Municipal Committee in the wake of the January Storm. During a struggle session, Cao was forced by the left-radical rebels to kneel on an overhead maintenance vehicle with his arms tied behind his back and a wooden sign hung around his neck, and paraded through busy downtown areas such as Nanjing Road, an act which exposed him to many risks of physical injury. On the orders of the Gang of Four, was labelled as a ''great traitor'' and subject to countless interrogations during his arrest.[2]
Cao was imprisoned for six years up till his transferring to the Municipal May 7 Cadre School for labour in May of 1973 as a result of there being insufficient evidence for him to be labelled as a traitor. His imprisonment led to immense physical and mental damage dealt to his health.[1][2]
On the 23rd of June 1978, with the approval of the CCP Central Committee, the CCP Shanghai Municipal Committee held a grand ceremony to rebury Cao's ashes, thoroughly rehabilitating him and restoring his political reputation. Cao's ashes were sent to Beijing by a special plane and placed in the Babaoshan Revolutionary Cemetery.[1]