We experimentally demonstrate the world’s first field-programmable gate-array-based real-time fiber nonlinearity compensator (NLC) using sparse K-means++ machine learning clustering in an energy-efficient 40-Gb/s 16-quadrature amplitude modulated self-coherent optical system. Our real-time NLC shows up to 3 dB improvement in Q-factor compared to linear equalization at 50 km of transmission.