A Chinese mine where 21 workers were killed on Thursday and 22 more remain trapped was being operated illegally.

Beijing will close its last three coal mines in the next four years and entirely quit coal mining by 2020, sources with the Beijing Municipal Commission of Development and Reform said Thursday.

In 2016, Beijing closed two coal mines with a total annual production capacity of 1.8 million tonnes, said Li Bin, deputy director of the coal management office at the commission.

By 2020, Beijing will completely bid farewell to the coal mining industry, the Chinese news agency Xinhua reported, quoting Li.

Beijing has a coal mining history of nearly 800 years. The earliest official historical documents on coal mining date from the Yuan Dynasty(1271-1368), Li said, adding that during the following Ming and Qing dynasties, west Beijing's mountainous area became renowned as a high-quality coal production base.

Since the founding of the People's Republic of China in 1949, coal produced in west Beijing's mountainous area has served as a major energy source for the capital's social and economic development, said Geng Yangmou, chairman of Beijing Haohua Energy Resource.

Statistics show that Beijing's coal consumption in 2010 was over 26 million tonnes, with the number declining to about 12 million tonnes in 2015.

Geng said the central and the Beijing municipal governments allocated more than 160 million yuan (23.2 million US dollars) in subsidies to local coal workers and miners in 2016.

Geng said the coal mining areas will be developed, as new industries are expected to be brought in.