Patients. Medical and surgical patients admitted to intensive care unit with 18 years of age or older in weaning from their first episode of mechanical ventilation for more than 24 hours were included. Patients with structural neurological disorder, acute toxic-metabolic neurological encephalopathy with neurological deficit \[estimated by a Glasgow Coma Score \<14 points\] at the time of weaning, neuromuscular disease, chronic obstructive pulmonary disease receiving non-invasive ventilation, limitation of life support therapy during their admission, tracheostomized patients, spinal cord injuries, scheduled surgical procedure during the 48 hours following extubation, intensive care unit readmission, transfer to another centre or a contraindication to non-invasive ventilation were excluded.

Weaning protocol. The beginning of weaning was considered when patients were conscious, without pain, connected to mechanical ventilation in pressure support ventilation mode, fraction of inspired oxygen ≤0.5, positive end-expiratory pressure +5cmH20, dopamine ≤5 mcgr/kg/min or noradrenaline ≤0.2 mcgr/kg/min, temperature \<38ºC and absence of metabolic acidosis. Weaning consisted of a spontaneous breathing trial, which is routinely performed in our unit with a T-tube connected to an oxygen source . The following conditions indicated a successful spontaneous breathing trial: oxygen partial pressure ≥60 mmHg or transcutaneous oxygen saturation\>90% with fraction of inspired oxygen \<0.5, carbon dioxide partial pressure \<50 mmHg (or an increase \<8 mmHg), pH \>7.32, respiratory rate \<35 bpm (or an increase \<50%), heart rate \<140 bpm (or an increase \<20%), systolic blood pressure \<180 mmHg, and absence of cardiac arrhythmias after a minimum period of 30-120 min. Once the test was completed, extubation and subsequent placement of a Venturi oxygen mask with 0.3-0.4 fraction of inspired oxygen was performed. The physician in charge was responsible for the process of removal of mechanical ventilation and subsequent extubation. In the case of T-tube test failure, the patient was reconnected to the ventilator. Patient who presented clinical deterioration within 48 hours after extubation (work of breathing, use of accessory muscles, paradoxical breathing) and/or respiratory-gasometric deterioration \[respiratory rate \>25 bpm or increase of \>50% with respect to the baseline respiratory rate, oxygen partial pressure \<65 mmHg, carbon dioxide partial pressure \>45 mmHg or pH \<7.33) \[19\] and who were candidates for non-invasive ventilation were included in the study. Extubation failure was classified as follows: 1) Acute respiratory failure secondary to airway problems: obstruction of the upper airway and aspiration or excess of secretions; 2) Acute respiratory failure not dependent of the airway: acute pulmonary oedema, congestive heart failure, hypoxemic and/or hypercapnic acute respiratory failure, encephalopathy and others (digestive bleeding, shock, etc.). Patients who required immediate reintubation after extubation failure were not included.

After confirming extubation failure and the possibility of eligibility to participate in the study, the patient was assigned to a group (non-invasive ventilation group or oxygen group) through the opening of a sealed envelope. Previously, a simple randomisation by a computerised system had been performed by a physician not involved in the study.

Non-invasive ventilation. BiPAP Vision and continuous positive airway pressure devices were used. For the BiPAP Vision, oronasal and facial masks and an active humidification system were used. Procedure: Once the patient was informed of the procedure, the type of mask was selected according to the clinical situation and anatomy of the patient, and the harness was placed. Ventilation was initiated with progressive levels of inspiratory positive airway pressure and expiratory positive airway pressure until a minimum inspiratory positive airway pressure of 10-15 cmH2O and an expiratory positive airway pressure of 5-6 cmH2O were achieved in the first hour. The rise time was 0.1-0.2 seconds. Continuous positive airway pressure. A continuous positive airway pressure device was used through the oronasal mask on the patient. The minimum initial positive end-expiratory pressure level was 5 cmH2O, with progressive increases up to 10-15 cmH2O. The objective pressures of both devices were set to reduce dyspnoea and respiratory mechanics, with an respiratory rate between 25 and 28 bpm. The fraction of inspired oxygen was increased in both devices until a transcutaneous oxygen saturation of 94-96% was achieved. Once the patient's cooperation and sufficient adaptability were achieved, the mask was adjusted to the harness with adjustable straps.

Oxygen therapy. The control group received oxygen therapy using a Venturi mask with an fraction of inspired oxygen up to 0.5 or using a reservoir mask connected to a high-flow flowmeter with 30 L/min of O2 (estimated fraction of inspired oxygen of 1.0).

Both non-invasive ventilation/continuous positive airway pressure and oxygen therapy were maintained continuously (except for hygiene or oral intake) until the patient exhibited improvement from the clinical and/or gasometric perspective. Withdrawal of non-invasive ventilation/continuous positive airway pressure was performed progressively with reduction of inspiratory airway pressure/expiratory positive airway pressure or positive end-expiratory pressure levels until complete disconnection of non-invasive ventilation. In both groups (study and control), after improvement, the fraction of inspired oxygen of the Venturi mask was set to 0.3-0.4. The criteria for failure of both non-invasive ventilation and oxygen therapy were: absence of clinical improvement (respiratory rate\>35 bpm, use of accessory muscles, thoracoabdominal asynchrony, encephalopathy) or deterioration of oxygenation (decrease in oxygen partial pressure or in oxygen partial pressure to fraction of inspired oxygen ratio), haemodynamic (noradrenaline \>0.5 mcgr/kg/min) or ventilation (increase in carbon dioxide partial pressure and decrease in pH) parameters. Modifications of fraction of inspired oxygen and inspiratory positive airway pressure/expiratory positive airway pressure or positive end-expiratory pressure levels, as well as the time of orotracheal intubation were performed according to the criteria of the physician. All patients received aspiration of secretions, postural changes, incentive spirometry and bronchodilators.

Parameters analysed. After inclusion in the study, demographic data, the reason of mechanical ventilation, severity according to the Simplified Acute Physiology Score 3, organ failure according to the Sequential Organ Failure Assessment scale (both of them at intensive care unit admission) and comorbidities were recorded. The duration both of mechanical ventilation until the first extubation and time of spontaneous breathing trial were measured. Neurological variables (Glasgow Coma Score), haemodynamic variables \[systolic blood pressure, diastolic blood pressure, mean blood pressure, heart rate\], respiratory variables (respiratory rate, transcutaneous oxygen saturation) and blood gases (oxygen partial pressure, fraction of inspired oxygen, oxygen partial pressure to fraction of inspired oxygen ratio, carbon dioxide partial pressure, pH, bicarbonate and lactic acid) were recorded during the T-test of patients eligible to participate in the study and later, when they presented acute respiratory failure due to extubation failure. Similarly, ventilatory parameters were recorded during the 1st,2nd, and 8th hours of randomisation. Time from extubation to acute respiratory failure extubation failure was recorded. After extubation failure, the following variables were recorded: reintubation, tracheostomy, organ failure (cardiovascular, coagulation, renal, liver, neurological) using the Sequential Organ Failure Assessment scale and infectious complications (pneumonia or tracheobronchitis associated to mechanical ventilation, urinary tract infection, bacteraemia) were determined. Also the duration both of non-invasive ventilation. and oxygen therapy and globally of mechanical ventilation, were calculated. The mortality rates in the intensive care unit, in the hospital, and at 90 days were determined.

Sample size. Based on previous results, it was considered that the need for intubation could be reduced by 35%. The estimated sample size was 30 patients in each group \[NIV group vs oxygen therapy\] with a confidence interval \[1-α\] of 95% and power \[1-β\] of 80%. Comparative analyses were conducted using Student's t test or the Mann-Whitney test for the comparisons of quantitative variables for parametric and non-parametric characteristics, respectively. For qualitative variables, chi-square statistic or Fisher's exact test were used. Differences were considered significant if P \<0.05. A per protocol analysis was performed. Multivariate analysis for repeated measures (with Bonferroni's correction) was performed with the aim of studying the influence either of NIV or oxygen therapy on respiratory parameters. The cumulative probability of survival was assessed using a Kaplan-Meier estimation of survival and a log-rank test to compare the two groups. The data were analysed using the statistical package SPSS 20.0.