Shanghai County (simplified Chinese: 上海县; traditional Chinese: 上海縣; pinyin: Shànghǎi Xiàn) was a county in modern-day Shanghai Municipality, in China. Shanghai County was first established in 1292 and finally abolished in 1992. Shanghai County was for most of its existence a part of Songjiang Prefecture, in Jiangsu Province, but later became a county under Shanghai Municipality. Shanghai County was historically the governing authority of the Shanghai's urban area and neighbouring areas. Its extent reduced with the establishment of the Shanghai Special Municipality and, later, Shanghai Municipality. Immediately before abolition, the county extended over a crescent-shaped area adjacent to, and surrounding, the southwest of Shanghai's city centre.
In 1290, Busa Hanwen (僕散翰文), the Jurchen governor of Songjiang Prefecture requested that Kublai Khan, as the Shizu emperor of Yuan, approve the division of Huating County into two, on the basis of administrative difficulty due to Huating's large area and dense population. The request was approved by the Yuan court in 1291 and Shanghai County was established in 1292. The first permanently appointed county governor, Zhou Ruji, arrived in 1294.
From 1845, due to the establishment of foreign concessions in Shanghai, the area under the effective control of Shanghai County gradually reduced. By 1911, the areas under the effective control of the County included the Old City (the county seat) and surrounding areas, Zhabei and Xuhui, as well as the docklands by the Huangpu River which are today the central and northern part of Yangpu District, the western part of Changning District and the riverside part of Pudong District, as well as the western suburbs which are today part of Minhang District. These areas were known as the "Chinese area" of Shanghai.
In 1927, Northern Expedition forces took over Shanghai. The Nationalist government established Shanghai Special Municipality in order to assert overarching Chinese control in Shanghai. The Special Municipality's seat was soon moved from the Old City to the Xujiahui area. In 1930, Shanghai Special Municipality was elevated to the same level as Shanghai County, both under Jiangsu Province, and the seat of Shanghai County was moved to Minhang township. During the Second Sino-Japanese War, Shanghai County was abolished in 1939, but re-established at the end of the war in 1945.
Under the People's Republic, various counties of Jiangsu Province, including Shanghai County, were handed to the province-level Shanghai Municipality in 1958. In the same year, various neighbouring townships and villages were moved into Shanghai County.In 1959, the new industrial area and township that formed Minhang Satellite City was carved out of Shanghai County to become Minhang District. Minhang District was absorbed into Xuhui District in 1964, but re-established in 1981.
Throughout the 1980s, as urbanisation changed the character of Shanghai County, more of the county was moved into surrounding districts of Shanghai Municipality, or established as new development zones. In 1992, the remaining part of Shanghai County was merged with Minhang District to become the new Minhang District.