A controller for an internal combustion engine , wherein the internal combustion engine includes a fuel injection valve that injects fuel to supply the fuel into a combustion chamber , an intake passage connected to the combustion chamber , and an intake valve that opens and closes the intake passage , and the internal combustion engine is configured to allow a closing timing of the intake valve to be retarded from a bottom dead center timing, the controller comprising processing circuitry configured to execute a calculating process that calculates a returned air amount (Gr(n)), which is an amount of air that flows into the combustion chamber and returns to the intake passage before the intake valve closes, a calculating process that calculates a returned fuel amount (Qr(n)) by multiplying a first fuel amount (Q1(n)), which is calculated based on a maximum air amount (Gm(n)) that is a maximum value of an amount of air flowing into the combustion chamber in one combustion cycle, by a value obtained by dividing the returned air amount by the maximum air amount, a calculating process that calculates a return correction amount (ΔQ(n)) based on the first fuel amount, a second fuel amount (Q2(n)), and a previous cycle's returned fuel amount (Qr(n-1)), the second fuel amount being calculated based on a closed-valve intake air amount (Mc(n)), and an operating process that operates the fuel injection valve to inject fuel, an amount of the injected fuel being obtained by correcting the second fuel amount using the return correction amount, so that an air-fuel ratio of a mixture that is burned in the combustion chamber is controlled to a target value, wherein the operating process includes under a condition in which the returned air amount is increased, having the fuel injection valve inject fuel increased in amount from a constant fuel amount, wherein the constant fuel amount is an amount of fuel injected when the returned air amount is unchanged, and under a condition in which the returned air amount is decreased, having the fuel injection valve inject fuel decreased in amount from the constant fuel amount. a calculating process that calculates a returned air amount (Gr(n)), which is an amount of air that flows into the combustion chamber and returns to the intake passage before the intake valve closes, a calculating process that calculates a returned fuel amount (Qr(n)) by multiplying a first fuel amount (Q1(n)), which is calculated based on a maximum air amount (Gm(n)) that is a maximum value of an amount of air flowing into the combustion chamber in one combustion cycle, by a value obtained by dividing the returned air amount by the maximum air amount, a calculating process that calculates a return correction amount (ΔQ(n)) based on the first fuel amount, a second fuel amount (Q2(n)), and a previous cycle's returned fuel amount (Qr(n-1)), the second fuel amount being calculated based on a closed-valve intake air amount (Mc(n)), and an operating process that operates the fuel injection valve to inject fuel, an amount of the injected fuel being obtained by correcting the second fuel amount using the return correction amount, so that an air-fuel ratio of a mixture that is burned in the combustion chamber is controlled to a target value, wherein the operating process includes under a condition in which the returned air amount is increased, having the fuel injection valve inject fuel increased in amount from a constant fuel amount, wherein the constant fuel amount is an amount of fuel injected when the returned air amount is unchanged, and under a condition in which the returned air amount is decreased, having the fuel injection valve inject fuel decreased in amount from the constant fuel amount. <EOS>