A method is disclosed for controlling the milking by a milking machine. The milking machine comprising at least one teat cup connected to a source of vacuum via a milk tube. During milking a milking vacuum in the milk tube is kept at a selected level and a maximum pulsation vacuum is kept at a selected level. During a terminating phase the milking vacuum is lowered to a lower level (8L) and the maximum pulsation vacuum is lowered to a lower level (9L) in order to terminate the milking. The milking vacuum is then lowered to a second lowered level (10L) to prevent milk from flowing backwards in the milking tube.