Japan's parliament has passed a one-off bill to allow Emperor Akihito to abdicate, the first emperor to do so in 200 years.
The 83-year-old said last year that his age and health were making it hard for him to fulfil his official duties.
But there was no provision under existing law for him to stand down.
The government will now begin the process of arranging his abdication, expected to happen in late 2018, and the handover to Crown Prince Naruhito.
Akihito, who has had heart surgery and was treated for prostate cancer, has been on the throne in Japan since the death of his father, Hirohito, in 1989.
In a rare address to the nation last year, he said he was beginning to feel "constraints" on his health which were making it hard for him to fulfil his official duties.
The emperor is constitutionally barred from making any political statements, so he could not say explicitly that he wanted to stand down as that would be considered comment on the law.
The newly passed law says that on abdication, the emperor's 57-year old son, Naruhito, will immediately take the Chrysanthemum Throne, but that neither he nor his successors would be allowed to abdicate under the law.
The government is yet to set a date for the abdication, but the bill says it must take place within three years of the law coming into effect.
The handover is widely expected take place in December 2018.
What does the emperor do? The emperor has no political powers but several official duties, such as greeting foreign dignitaries. Japan's monarchy is entwined in the Shinto religion and the emperor still performs religious ceremonies.
What do the public think? Most support the emperor's desire to abdicate - a survey by the Kyodo news agency after Akihito suggested he wanted to step down found more than 85% saying abdication should be legalised.
Are there more debates revision of the law of royal succession? A discussion about whether or not a woman would be able to ascend the throne was triggered in 2006 when the emperor had no grandsons, but was postponed after a boy was born to the imperial family.