To figure out porosity evolution mechanisms of marine shales inside and at the margin of the Sichuan Basin, South China, we measured samples selected from Lower Cambrian Qiongzhusi shales and Lower Silurian Longmaxi shales by a combination of X-ray diffraction, geochemistry measurement, focused ion beam milling and scanning electron microscopy imaging, and adsorption. It was suggested that shales of the upper Qiongzhusi Formation (a marine shallow continental-shelf setting) and the Longmaxi Formation (a marine abyssal continental-shelf setting) possessed larger pore volumes and larger pore surface areas than those of the lower Qiongzhusi Formation (a marine abyssal continental-shelf setting). Pores, in terms of pores of mineral frameworks, pores associated with clay minerals, dissolved pores, and organic matter (OM)-hosted pores, were all observed in the upper Qiongzhusi Formation and Longmaxi Formation, whereas none of the four types of pores developed well in the bottom of the Qiongzhusi Formation. Moreover, migrated OM is superior to depositional OM in the contribution of the pore space, in terms of pore productivity and pore protection. Good sealing abilities of the upper Qiongzhusi Formation and Longmaxi Formation allow more migrated OM and gaseous hydrocarbon retention than the lower Qiongzhusi Formation with an unconformity beneath acting as a channel of liquid and gaseous hydrocarbon migration, which bring about better pore properties. Finally, through the above analysis, the pore evolution mode has been established to gain insights for mechanisms of destruction, formation, and preservation of pores ranging from original sedimentary to metamorphic stage (–). Mechanisms of pore destruction contain mechanical compaction, chemical cementation, and OM carbonation. Mechanisms of pore generation comprise thermal pyrolysis of OM, transformation of clay minerals, and dissolution of soluble minerals. Mechanisms of pore preservation include mechanical stability of rigid grains, chemical stability of hydrophobic OM, and gas supporting through overpressure.