The triple bypass operation went “without incident”, Lucia Alonso, the manager of the private hospital in Madrid, told the media.
“As is customary for this type of procedure, the patient has been referred to the intensive care unit for post-op monitoring,” she said in a statement broadcast on Spanish public television.
King Felipe VI appeared relaxed and smiling when he arrived at the hospital at midday along with his mother, former Queen Sofia.
When the 81-year-old Juan Carlos arrived at the hospital on Friday for the operation, he told the press: “You'll see me on the way out.”
Spanish Prime Minister Pedro Sanchez on Twitter hailed that “Juan Carlos' operation had gone as planned”, adding that he hoped the former monarch would have a quick recovery.
Doctors had detected that the former king needed the operation during an annual check-up in June.
Juan Carlos, who helped smooth Spain's transition to democracy in the 1970s after the Francisco Franco dictatorship, abdicated in favour of his son Felipe in 2014.
Despite having retired from public life, he has continued to be spotted in public at bullfights in Madrid and at a sailing competition in Finland.
He underwent a knee operation last year and has had multiple hip operations.