Magnesium hydroxide½MgðOHÞ2is a commonly used chemical for controlling corrosion and odor problems in sewers by reducingthe transfer of hydrogen sulfide from the liquid to the gas phase through pH elevation. The effectiveness of many current dosing practices isunsatisfactory due to negligence of the dynamics of sewage flow and characteristics, and their effects on sewage pH. This paper reports the designand validation of the first online control algorithm for MgðOHÞ2dosing to sewers. The control algorithm consists of a combination of feedfor-ward and feedback loops. A feedback controller is used to calculate the MgðOHÞ2dosing rate to raise the sewage pH at the pumping station to theset-point. A feedforward controller is then used to calculate the additional MgðOHÞ2dose based on the prediction of acid production in thedownstream sewer pipe due to in-sewer processes. A further feedback controller is used to adjust the MgðOHÞ2dosing rate to correct the errorbetween the sewage pH at the end of the pipe and the pH set-point. Following comprehensive assessment using modeling and simulation, thecontrol was successfully validated and its effectiveness demonstrated in a 2-month field study. The online control algorithm reduced the variationof pH at the discharge point, i.e., from8.730.21to8.590.10. In addition to improved sulfide control, the controller also resulted in 15%saving in chemical consumption, leading to significant financial benefits and lower environmental footprint. It was also found that the sewageflow rate should be predicted online for sewers influenced by rainwater infiltration as the variation of flow rate and sewage dilution are importantdisturbances for the controller.