A closed-loop drilling system and method of drilling oil, gas, or geothermal wells is described, whereby through the control of the flow rates in and out of the wellbore, and by adjusting the pressure inside the wellbore by a pressure/flow control device installed on the return line, surface pressure being increased or decreased as required, this in turn decreasing or increasing downhole pressure, occurrence of kicks and fluid losses may be greatly minimized and quickly controlled. Through the method of the invention the elimination of the kick tolerance and tripping margin on the design of the well is made possible, since the pore and fracture pressure will be determined in real-time while drilling the well, and, therefore, nearly no safety margin is necessary when designing the well, reducing significantly the number of casing strings necessary. The inventive method can be called intelligent safe drilling since the response to influx or fluid loss is nearly immediate and so smoothly done that the drilling can go on without any break in the normal course of action. The new method is applicable to the whole wellbore from the first casing string with a BOP connection, and it can be implemented and adopted to any rig or drilling installation that uses the conventional method with very few exceptions and limitations. The new method is applicable to all types of wells, onshore, offshore, deepwater and ultra-deepwater, with huge safety improvement in difficult drilling scenarios.