A control device for an engine provided with an engine body where a cylinder is formed, and an exhaust passage through which exhaust gas discharged from the engine body flows, the control device comprising: a NO x sensor disposed in the exhaust passage and configured to detect a concentration of NO x in the exhaust gas; an injector configured to change an air-fuel ratio inside the cylinder; a control valve (13a, 14a, 61) configured to change a temperature inside the cylinder; and a controller configured to control the injector and the control valve (13a, 14a, 61), wherein the controller is configured to control the injector based on a detection value of the NO x sensor to variably set the air-fuel ratio inside the cylinder, and configured to cause, when a particular condition that the air-fuel ratio inside the cylinder is leaner than a preset upper limit is satisfied, the control valve (13a, 14a, 61) to raise the temperature inside the cylinder, wherein the controller is configured to control the injector so that partial compression ignition combustion in which spark ignition combustion of a portion of a mixture gas inside the cylinder is forcibly carried out by spark ignition, and compression ignition combustion of the remaining mixture gas inside the cylinder is then carried out by self-ignition is performed at least in a part of an operating range of the engine, wherein the controller is configured to control the injector based on the detection value of the NO x sensor at least in a part of the operating range where the partial compression ignition combustion is performed, wherein the controller is configured to correct a target air-fuel ratio that is a target value of the air-fuel ratio inside the cylinder based on the detection value of the NO x sensor, and configured to control the injector so that the corrected target air-fuel ratio is achieved, wherein the controller is configured to determine, when the corrected target air-fuel ratio becomes leaner than the upper limit, that the particular condition is satisfied, wherein the control valve includes an exhaust shutter valve provided in the exhaust passage and configured to open and close the exhaust passage, and wherein the controller is configured to control, when the particular condition is satisfied, the exhaust shutter valve to adjust an opening of the control valve, wherein the controller is configured to control, when the particular condition is satisfied, the exhaust shutter valve to adjust the opening of the control valve to be smaller. a NO x sensor disposed in the exhaust passage and configured to detect a concentration of NO x in the exhaust gas; an injector configured to change an air-fuel ratio inside the cylinder; a control valve (13a, 14a, 61) configured to change a temperature inside the cylinder; and a controller configured to control the injector and the control valve (13a, 14a, 61), wherein the controller is configured to control the injector based on a detection value of the NO x sensor to variably set the air-fuel ratio inside the cylinder, and configured to cause, when a particular condition that the air-fuel ratio inside the cylinder is leaner than a preset upper limit is satisfied, the control valve (13a, 14a, 61) to raise the temperature inside the cylinder, wherein the controller is configured to control the injector so that partial compression ignition combustion in which spark ignition combustion of a portion of a mixture gas inside the cylinder is forcibly carried out by spark ignition, and compression ignition combustion of the remaining mixture gas inside the cylinder is then carried out by self-ignition is performed at least in a part of an operating range of the engine, wherein the controller is configured to control the injector based on the detection value of the NO x sensor at least in a part of the operating range where the partial compression ignition combustion is performed, wherein the controller is configured to correct a target air-fuel ratio that is a target value of the air-fuel ratio inside the cylinder based on the detection value of the NO x sensor, and configured to control the injector so that the corrected target air-fuel ratio is achieved, wherein the controller is configured to determine, when the corrected target air-fuel ratio becomes leaner than the upper limit, that the particular condition is satisfied, wherein the control valve includes an exhaust shutter valve provided in the exhaust passage and configured to open and close the exhaust passage, and wherein the controller is configured to control, when the particular condition is satisfied, the exhaust shutter valve to adjust an opening of the control valve, wherein the controller is configured to control, when the particular condition is satisfied, the exhaust shutter valve to adjust the opening of the control valve to be smaller.