The present invention relates to a method of treating porous and permeable underground formations or cavities of reservoir rock or sand foundation type. The method consists in injecting a liquid composition comprising microgels into the formations in order to reduce the production of water, gas or sands, and/or for zone abandonment.