This work addresses operational management optimization problems in wastewater treatment plants. We developed a novel technology that allows control of such plants, based on real-time sensor readings, with cloud computing at the front end and state-of-the-art operations research and data science algorithms at the back end. We used a constrained Markov decision process as the key optimization framework. We tested our technology in a one-year pilot at a plant in Lleida, Spain, operated by Aqualia, the world's third-largest water company. The results showed a dramatic 13.5 percent general reduction in the plant's electricity consumption, a 14 percent reduction in the amount of chemicals needed to remove phosphorus from the water, and a 17 percent reduction in sludge production. Moreover, results showed a significant improvement in total nitrogen removal, especially in low temperature conditions.