Once popular Juan Carlos, who helped smooth Spain's transition to democracy in the 1970s after the Francisco Franco dictatorship, has lost public support in recent years due to corruption scandals and gaffes.
His daughter, Princess Cristina, and her husband, Inaki Urdangarin, are under investigation in a corruption case. Both deny any wrongdoing. A judge in Palma de Mallorca is expected to decide soon whether to put Urdangarin on trial on charges of embezzling 6 million euros in public funds through his charity.
Read MoreSpain's Princess Cristina charged with tax fraud, money-laundering
The 76-year-old king, whose health is failing and has had five operations in two years, including hip replacement surgery, is stepping down for personal reasons, Rajoy said.
Spain does not have a precise law regulating abdication and succession. Rajoy said his cabinet would meet very soon to set out the steps for Prince Felipe to take over as Felipe VI.
The country is just pulling out of a difficult and long recession that has seen faith in politicians, the royal family and other institutions all dwindle.