The residual ions of the acid cleaning processes induce the further corrosion of the metals, and this could be minimized using green inhibitors. Alkaloids extracted from plant parts could be cost effective and efficient inhibitors. In this work, alkaloids from Solanum xanthocarpum stem were successfully extracted, and they were characterized by qualitative chemical tests and spectroscopic measurements. As-extracted alkaloids were employed as green corrosion inhibitors for mild steel. The effectiveness of the inhibitor was determined by the weight loss and electrochemical measurement methods. From the weight loss measurement, the maximum inhibition efficiency of 93.14% was achieved. The temperature effect study revealed that the inhibitor can work up to a temperature of 58 °C. This could be one of the highest working temperatures among the reported green inhibitors. The electrochemical measurement reveals that the alkaloids could inhibit effectively up to 98.14% of the corrosion and serve as a mixed-type green inhibitor. A study on the kinetic parameters reflects that the inhibitor forms a potential barrier for the protection of a mild steel surface against corrosion. The values obtained from the thermodynamic parameters study reflect that the process is a spontaneous endothermic process. Based on the findings, it is revealed that the alkaloids extracted from S. xanthocarpum can serve as an excellent, eco-friendly and a promising green inhibitor against mild steel corrosion.