A controller for an engine having: a sensor configured to detect an actuation state of a service brake; a sensor configured to detect the actuation state of a parking brake; a sensor configured to detect a gear shift state of an automatic transmission; and a control unit configured to control an engine at a vehicle stopping time, according to output signals of the sensors, wherein the control unit is configured to execute a first engine stopping process of stopping the engine when a first condition that the service brake is released, and the parking brake is actuated, and the automatic transmission is shifted into neutral has been established, and a second engine stopping process of stopping the engine when a second condition that the service brake is actuated and the automatic transmission is shifted to a forward gear has been established, wherein the control unit changes the stored first condition or the stored second condition that has stopped the engine, according to changes in actuation state of the service brake, in actuation state of the parking brake and in gear shift state of the transmission, wherein in a case where the engine has been stopped by establishment of the first condition, the control unit changes the condition that has stopped the engine to the second condition, when the service brake has been actuated, the parking brake has been released, and the transmission has been shifted to the forward gear, and wherein in a case where the engine has been stopped by establishment of the second condition, the control unit changes the condition that has stopped the engine to the first condition, when the service brake has been released, the parking brake has been actuated, and the transmission has been shifted into neutral. a sensor configured to detect an actuation state of a service brake; a sensor configured to detect the actuation state of a parking brake; a sensor configured to detect a gear shift state of an automatic transmission; and a control unit configured to control an engine at a vehicle stopping time, according to output signals of the sensors, wherein the control unit is configured to execute a first engine stopping process of stopping the engine when a first condition that the service brake is released, and the parking brake is actuated, and the automatic transmission is shifted into neutral has been established, and a second engine stopping process of stopping the engine when a second condition that the service brake is actuated and the automatic transmission is shifted to a forward gear has been established, wherein the control unit changes the stored first condition or the stored second condition that has stopped the engine, according to changes in actuation state of the service brake, in actuation state of the parking brake and in gear shift state of the transmission, wherein in a case where the engine has been stopped by establishment of the first condition, the control unit changes the condition that has stopped the engine to the second condition, when the service brake has been actuated, the parking brake has been released, and the transmission has been shifted to the forward gear, and wherein in a case where the engine has been stopped by establishment of the second condition, the control unit changes the condition that has stopped the engine to the first condition, when the service brake has been released, the parking brake has been actuated, and the transmission has been shifted into neutral.