The Real Madrid midfielder had already pulled out of Spain's Confederations Cup squad due to the groin injury and will be out for around two months of pre-season
The Spain international missed Madrid's last two Liga games due to the injury.
"Real Madrid player Xabi Alonso was successfully operated upon on [Friday] morning for an athletic pubalgia," read a statement on the club's official website.
"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.