The 31-year-old travelled to Munich to have the operation carried out by a specialist and, although Real insisted it had been successful, it is not yet known whether the former Liverpool man will be fit to take a full part in pre-season training.
"Xabi Alonso has had a successful operation on a sports hernia this morning," said a statement on the club's website.
"The surgery was carried out by a specialist in this field, Doctor Ulrike Muschawek of the Hernia Centre in Munich.
"The operation was supervised at all times by the Real Madrid medical team."
Alonso made 47 appearances for Real this season, but was severely hampered by injuries in the second half of the campaign as he also missed a number of games due to a back injury.