Profile: Spain's Juan Carlos
Juan Carlos played a pivotal role in Spain's transition to democracy after General Francisco Franco's death in 1975.
But his popularity and his health declined in the final years of his reign, and with Prince Felipe already groomed to succeed him, the decision to abdicate at the age of 76 will not have shocked the country.
Born in exile in 1938, he was allowed to attend a Spanish school in Madrid before joining the military and attending university. He married Princess Sofia of Greece in 1962.
Juan Carlos came to the throne promising to be "king of all Spaniards, without exception" in November 1975, chosen by Franco years before as his successor.
He ignored Franco's supporters, who wanted an extension to autocratic rule, and ushered in a new system of parliamentary monarchy.
With the help of a clever constitutional lawyer the king skilfully avoided alienating the military, says Prof Paul Preston, a Spain historian at the London School of Economics.
King Juan Carlos gave the impression until mid-1976 that he would not betray his oath to the late Gen Franco - an oath to maintain the dictatorship.
But little more than five years after he came to the throne, Spain was plunged into political confusion, when a group of civil guard officers led by Lt-Col Antonio Tejero Molina stormed the lower house of parliament, the Cortes, taking hundreds of MPs hostage.
Weeks earlier, Prime Minister Adolfo Suarez, who had led Spain since Franco's death, had resigned in the face of increasing security and economic problems.
For hours, Spain's embryonic democracy was in jeopardy. But the king told the civil service to take on the role of parliament from the Zarzuela Palace and the rebels eventually surrendered, when it became clear they did not have widespread support within the armed forces.
At 01:15 on 24 February, Juan Carlos went on national TV, dressed in military uniform, to say the coup would not be tolerated. For Spaniards, that action defined his 39-year reign.
In a rare interview with Spanish TV in 2000, he spoke of his desire for "the monarchy to be open and close to the people, for many people to be able to reach the King, the Queen - in short, for them to be able to see us, to be able to talk to us, to be able to speak to us".
"From the outset, I knew that the monarchy could not be anything other than democratic. But the problem was, how to bring it about? This I did not know."
He had three children, Felipe, Cristina and Elena. But in recent years his marriage to Sofia had come under strain and it was a hunting trip to Botswana in 2012 without her that led to a dramatic decline in his reputation. Photos were published in Spanish media of the king standing with a gun beside a dead elephant.
A German divorcee, Corinna zu Sayn-Wittgenstein, was said to have been on the expedition but denied any "improper relationship" with the king.
The trip might have stayed secret but for a fall he suffered in Botswana. The king had to be flown home for surgery for a hip fracture.
With Spain in the middle of economic crisis and one in four people unemployed, there was a public outcry and there were some calls for him to abdicate.
As he left hospital in Madrid, he made his first-ever public apology: "I have made a mistake and it won't happen again."
But the royal family's troubles continued with a long-running investigation into the business affairs of the king's youngest daughter's husband.
The Infanta Cristina herself had to appear in court in March 2014 as a formal suspect in the embezzlement case of her husband, the Duke of Palma Inaki Urdangarin.
Although the royal household tried to separate the king from the scandal, an opinion poll in January 2014 suggested that 62% of Spaniards would like to see him abdicate.
He appeared at an annual military event and struggled through a speech, his ill-health plain to a national audience.
Prof Preston says the king appears to have decided that for the monarchy to survive he had to move sooner rather than later. The monarchy's image has been stained by corruption scandals among Spain's ruling elite, he says, while many ordinary people suffer economic hardship.
Explaining his abdication in his 2 June TV address, Juan Carlos said he had first considered stepping down in January and had made his decision to make way for "a new generation".
Announcing the king's abdication, Prime Minister Mariano Rajoy said in tribute: "For 39 years he was the best symbol of our peaceful co-existence. His figure is so closely linked to democracy that one cannot be understood without the other."