A controller for an internal combustion engine , the internal combustion engine including: a cylinder ; an intake passage including a connection port connected to the cylinder ; a water injection valve configured to inject water into the intake passage ; an intake valve configured to selectively open and close the connection port; and a crank chamber that connects to the cylinder and accommodates a crankshaft , wherein a period from when the intake valve closes to when the intake valve closes again after opening is referred to as a single cycle, the controller is configured to execute: a pressure calculation process that calculates pressure of gas in the crank chamber based on a running state of the internal combustion engine ; a first injection process that causes the water injection valve to inject a first injection amount of water when the intake valve is open in the single cycle; and a second injection process that causes the water injection valve to inject a second injection amount of water when the intake valve is closed in the single cycle, and the controller is configured to set a ratio of the first injection amount to a sum of the first injection amount and the second injection amount to a smaller value when the pressure is greater than or equal to a specified value than when the pressure is less than the specified value, the specified value being defined in advance. a cylinder ; an intake passage including a connection port connected to the cylinder ; a water injection valve configured to inject water into the intake passage ; an intake valve configured to selectively open and close the connection port; and a crank chamber that connects to the cylinder and accommodates a crankshaft , wherein a period from when the intake valve closes to when the intake valve closes again after opening is referred to as a single cycle, the controller is configured to execute: a pressure calculation process that calculates pressure of gas in the crank chamber based on a running state of the internal combustion engine ; a first injection process that causes the water injection valve to inject a first injection amount of water when the intake valve is open in the single cycle; and a second injection process that causes the water injection valve to inject a second injection amount of water when the intake valve is closed in the single cycle, and the controller is configured to set a ratio of the first injection amount to a sum of the first injection amount and the second injection amount to a smaller value when the pressure is greater than or equal to a specified value than when the pressure is less than the specified value, the specified value being defined in advance. a pressure calculation process that calculates pressure of gas in the crank chamber based on a running state of the internal combustion engine ; a first injection process that causes the water injection valve to inject a first injection amount of water when the intake valve is open in the single cycle; and a second injection process that causes the water injection valve to inject a second injection amount of water when the intake valve is closed in the single cycle, and the controller is configured to set a ratio of the first injection amount to a sum of the first injection amount and the second injection amount to a smaller value when the pressure is greater than or equal to a specified value than when the pressure is less than the specified value, the specified value being defined in advance. <EOS>