A method for operating an internal combustion engine including feeding a pilot quantity of gas fuel, into a prechamber before a piston reaches a top dead center position. The method comprises autoignition of the pilot quantity of gas fuel in the prechamber, feeding a main quantity of gas fuel into the prechamber after the autoignition, and ignition of the main quantity of gas fuel by the conditions in the prechamber that are brought about by the autoignited pilot quantity. The method makes it possible to operate an internal combustion engine purely with methane or some other gaseous fuel, by means of compression autoignition of the pilot quantity.