The combustion timing in internal combustion engines affects the fuel consumption, in-cylinder peak pressure, engine noise and emission levels. The combination of an in-cylinder pressure sensor together with a direct injection fuel system lends itself well for cycle-to-cycle control of the combustion timing.This paper presents a method of controlling the combustion timing by the use of a cycle-to-cycle injection-timing algorithm. At each cycle the currently estimated heat-release rate is used to predict the in-cylinder pressure change due to a combustion-timing shift.The prediction is then used to obtain a cycle-to-cycle model that relates combustion timing to gross indicated mean effective pressure, max pressure and max pressure derivative. Then the injection timing that controls the combustion timing is decided by solving an optimization problem involving the model obtained.The controller was experimentally tested on a Scania D13 heavy-duty diesel engine in the lower load range with a fuel mixture of 80 volume % gasoline and 20 volume % n-heptane.Controller-performance test results are presented for different controller and model parameter settings at three different operating points. The results show that the controller was consistent in converging to a combustion timing point that was dependent on the magnitude of the modeled heat transfer rate but not necessarily the same as the experimentally found most efficient point. The convergence rate of the controller could be set by varying a design parameter β, which is the controller resistance to changing the injection timing when moving towards a more efficient operating point. Choosing β was shown to be a trade-off between controller convergence speed and cycle-to-cycle variation. The controller was also able to fulfill predefined constraints on max pressure and max pressure derivative.