It is the latest in a string of blows for the king, who walks with a crutch and has appeared frail in recent months, while weathering corruption scandals that have damaged his popularity.
He will undergo the operation in Madrid in "the coming days", the head of the royal household Rafael Spottorno told a news conference.
"The king has at no time considered abdication," despite being examined by doctors over recent weeks due to pain in his left hip, he added, however.
"Treatment of an infected prosthesis is always through surgery. It consists of replacing the prosthesis," said Miguel Cabanela, a top Spanish orthopaedic surgeon from the Mayo Clinic in the United States, who will perform the operation.
More From This Section
"His majesty's general health is much better than average for patients of his age whom I have operated on. He is a very vigorous man, he takes very little medication," he added.
Juan Carlos is widely respected for steering Spain to democracy after the death of longtime dictator General Francisco Franco in 1975, and helping to quell an attempted military coup in 1981.
The king's son-in-law, Cristina's husband Inaki Urdangarin, has been under investigation since late 2011 for alleged embezzlement.
While the corruption scandal gained steam, Juan Carlos broke his hip during the secret African hunting trip and had to be flown home for medical care at a time when one in four Spaniards was out of work.
He issued a public apology after his return -- an unprecedented move for a Spanish king -- but the affair fuelled calls from some quarters for him to abdicate in favour of his 45-year-old-son, Prince Felipe, the youngest of three children he has with Queen Sofia.