A method of sterilizing packages in production of the packages, wherein the packages have an open end and a closed end. A gaseous sterilizing agent is used and kept in the gaseous phase throughout the sterilization process and an ambient temperature and a concentration of sterilizing agent in a sterilization zone where sterilization is performed are measured and used for controlling the amount of sterilizing agent introduced in the sterilization zone.