We studied the structural, electronic, and magnetic properties of a cubic perovskite ${\mathrm{BaFeO}}_{3\ensuremath{-}\ensuremath{\delta}}$ ($0\ensuremath{\le}\ensuremath{\delta}\ensuremath{\le}0.5$) within the density-functional theory using a generalized gradient approximation (GGA) and a GGA + $U$ method. According to our calculations, ${\mathrm{BaFeO}}_{3}$ in its stoichiometric cubic structure should be half-metallic and strongly ferromagnetic, with an extremely high Curie temperature (${T}_{C}$) of 700--900 K. However, such an estimate of ${T}_{C}$ disagrees with all available experiments, which report that ${T}_{C}$ of the ${\mathrm{BaFeO}}_{3}$ and undoped ${\mathrm{BaFeO}}_{3\ensuremath{-}\ensuremath{\delta}}$ films varies between 111 and 235 K, or, alternatively, that no ferromagnetic order was detected there. Fitting the calculated x-ray magnetic circular dichroism spectra to the experimental features seen for ${\mathrm{BaFeO}}_{3}$, we concluded that good agreement can be obtained when oxygen vacancies are included in our model. Thus, the relatively low ${T}_{C}$ measured in ${\mathrm{BaFeO}}_{3}$ can be explained by oxygen vacancies intrinsically present in the material. Since iron species near the O vacancy change their oxidation state from $4+$ to $3+$, the interaction between ${\mathrm{Fe}}^{4+}$ and ${\mathrm{Fe}}^{3+}$, which is antiferromagnetic, weakens the effective magnetic interaction in the system, which is predominantly ferromagnetic. With increasing $\ensuremath{\delta}$ in ${\mathrm{BaFeO}}_{3\ensuremath{-}\ensuremath{\delta}}$, its ${T}_{C}$ decreases down to the critical value when the magnetic order becomes antiferromagnetic. Our calculations of the electronic structure of ${\mathrm{BaFeO}}_{3\ensuremath{-}\ensuremath{\delta}}$ illustrate how the ferromagnetism originates and also how one can keep this cubic perovskite robustly ferromagnetic far above room temperature.