Excess nitrogen (N) flowing from livestock manure to water systems poses a serious threat to the natural environment. Thus, livestock wastewater management has recently drawn attention to this related field. This study first attempted to obtain the optimal conditions for the further volatilization of NH3 gas generated from pig wastewater by adjusting the amount of injected magnesia (MgO). At 0.8 wt.% of MgO (by pig wastewater weight), the volatility rate of NH3 increased to 75.5% after a day of aeration compared to untreated samples (pig wastewater itself). This phenomenon was attributed to increases in the pH of pig wastewater as MgO dissolved in it, increasing the volatilization efficiency of NH3. The initial pH of pig wastewater was 8.4, and the pH was 9.2 when MgO was added up to 0.8 wt.%. Second, the residual ammonia nitrogen (NH4 +-N) in pig wastewater was removed by precipitation in the form of struvite (NH4MgPO4·6H2O) by adjusting the pH after adding MgO and H3PO4. Struvite produced in the pig wastewater was identified by field emission scanning electron microscopy (FE-SEM) and X-ray diffraction (XRD) analysis. White precipitates began to form at pH 6, and the higher the pH, the lower the concentration of NH4 +-N in pig wastewater. Of the total 86.1% of NH4 +-N removed, 62.4% was achieved at pH 6, which was the highest removal rate. Furthermore, how struvite changes with pH was investigated. Under conditions of pH 11 or higher, the synthesized struvite was completely decomposed. The yield of struvite in the precipitate was determined to be between 68% and 84% through a variety of analyses.