The holding midfielder had already pulled out of Spain's Confederations Cup squad due to the knock and will be out for around two months.
The Spain international missed Madrid's last two league games due to the injury, and he had already been left off Spain's FIFA Confederations Cup roster because of the ailment.
"Real Madrid player Xabi Alonso was successfully operated on this morning for an athletic pubalgia," a Madrid statement reads. "The surgery was carried out by a specialist in this condition, Dr. Ulrike Muschawek, from the Hernienzentrum in Munich. The operation was supervised throughout by Real Madrid Sanitas Medical Services."
The 31-year-old made 47 appearances in all competitions for Madrid in 2012-13.