It is very interesting and also a big challenge to encapsulate metal clusters within microporous solids to expand their application diversity. For this target, herein, we present an electrochemical synthesis strategy for the encapsulation of noble metals (Au, Pd, Pt) within ZIF-8 cavities. In this method, metal precursors of AuCl , PtCl , and PdCl are introduced into ZIF-8 crystals during the concurrent crystallization of ZIF-8 at the anode. As a consequence, very small metal clusters with sizes around 1.2 nm are obtained within ZIF-8 crystals after hydrogen reduction; these clusters exhibit high thermal stability, as evident from the good maintenance of their original sizes after a high-temperature test. The catalytic properties of the encapsulated metal clusters within ZIF-8 are evaluated for CO oxidations. Because of the small pore window of ZIF-8 (0.34 nm) and the confinement effect of small pores, about 80 % of the metal clusters (fractions of 0.74, 0.77, and 0.75 for Au, Pt, and Pd in ZIF-8, respectively) retain their catalytic activity after exposure to the organosulfur poison thiophene (0.46 nm), which is in contrast to their counterparts (fractions of 0.22, 0.25, and 0.20 for Au, Pt, and Pd on the SiO support). The excellent performances of metal clusters encapsulated within ZIF-8 crystals give new opportunities for catalytic reactions.