A breathing apparatus for ventilating the lungs of a patient with breathing gas, has: a breathing circuit configuration a mechanical ventilation system a manual ventilation system provided with a manual ventilation bag a manual ventilation valve for enabling manual ventilation of breathing gas from the breathing circuit a pressure sensor devised to detect the pressure level in the breathing circuit an electronically controlled expiration valve (40) that in a mechanical ventilation mode is controlled to control the pressure level in the breathing circuit according to a first set of predetermined control rules adapted to mechanical ventilation mode requirements said electronically controlled expiration valve in a manual ventilation mode being coupled to enable ventilation of breathing gas from the breathing circuit by means of the manual ventilation system according to a second set of predetermined control rules adapted to manual ventilation mode requirements. In a method for controlling a breathing apparatus, an electronic expiration valve is controlled during the mechanical ventilation mode as well as during the manual ventilation mode of the apparatus. The control of the expiration valve can be implemented by means of a software product for the breathing apparatus embodying programming instructions as control rules, which, when executed in the apparatus, enable control of the expiration valve during manual ventilation.