The law takes effect at midnight Wednesday, hours before the monarch's 46-year-old son is formally proclaimed as King Felipe VI.
Juan Carlos signed the measure during a brief ceremony at the royal palace in Madrid.
Prime Minister Mariano Rajoy added his signature and the departing monarch rose and turned to embrace Felipe.
Juan Carlos was visibly moved when the roughly 150 invited guests burst into applause.
The young daughters of Felipe and his wife, Princess Letizia, came forward to kiss the king and Queen Sofia before the ceremony ended with the playing of Spain's national anthem.
Felipe VI will be proclaimed king before Parliament Thursday morning, with the nearly 700 members of the lower house and Senate, the Cabinet and over 100 special guests in attendance.
Juan Carlos ascended to the throne Nov 22, 1975
Leonor, the eldest daughter of Felipe and Letizia, will automatically become Princess of Asturias and heir to the throne.
Juan Carlos ascended to the throne Nov 22, 1975, and Felipe de Borbon became Prince of Asturias in January 1977.