As an indispensable component of coal-fired power plants, boilers play a crucial role in converting water into high-pressure steam. The oxygen content in the flue gas is a crucial indicator, which indicates the state of combustion within the boiler. The oxygen content not only affects the thermal efficiency of the boiler and the energy utilization of the generator unit, but also has adverse impacts on the environment. Therefore, accurate measurement of the flue gas’s oxygen content is of paramount importance in enhancing the energy utilization efficiency of coal-fired power plants and reducing the emissions of waste gas and pollutants. This study proposes a prediction model for the oxygen content in the flue gas that combines the whale optimization algorithm (WOA) and long short-term memory (LSTM) networks. Among them, the whale optimization algorithm (WOA) was used to optimize the learning rate, the number of hidden layers, and the regularization coefficients of the long short-term memory (LSTM). The data used in this study were obtained from a 350 MW power generation unit in a coal-fired power plant to validate the practicality and effectiveness of the proposed hybrid model. The simulation results demonstrated that the whale optimization algorithm–long short-term memory (WOA-LSTM) model achieved an MAE of 0.16493, an RMSE of 0.12712, an MAPE of 2.2254%, and an R2 value of 0.98664. The whale optimization algorithm–long short-term memory (WOA-LSTM) model demonstrated enhancements in accuracy compared with the least squares support vector machine (LSSVM), long short-term memory (LSTM), particle swarm optimization–least squares support vector machine (PSO-LSSVM), and particle swarm optimization–long short-term memory (PSO-LSTM), with improvements of 4.93%, 4.03%, 1.35%, and 0.49%, respectively. These results indicated that the proposed soft sensor model exhibited more accurate performance, which can meet practical requirements of coal-fired power plants.