TOKYO — Japanese Emperor Akihito announced his abdication at a palace ceremony Tuesday in his final address, as the nation embraced the end of his reign with reminiscence and hope for a new era.

“Today, I am concluding my duties as the emperor,” Akihito said as he stood in front of the throne, as other members of the royal family and top government officials watched.

“Since ascending the throne 30 years ago, I have performed my duties as the emperor with a deep sense of trust in and respect for the people, and I consider myself most fortunate to have been able to do so. I sincerely thank the people who accepted and supported me in my role as the symbol of the state,” Akihito said in his last official duty as emperor.

As he walked out of the room following his speech and officials were taking away the imperial regalia in a box, Akihito turned around, paused and bowed to the audience.

His reign runs through midnight, when his son Crown Prince Naruhito, who observed Akihito’s abdication ceremony, becomes the new emperor and his era begins.

Naruhito will formally ascend the Chrysanthemum Throne on Wednesday. In a separate ceremony, he will receive the imperial regalia of sword and jewel as well as the imperial seals as proof of his succession as the nation’s 126th emperor, according to official palace count, which historians say could include mythical figures until around the 5th century.

Naruhito’s wife, Masako, and daughter Aiko are barred from the ceremony because they are female members of the royal family, a palace tradition that the government upheld despite criticism that it is out of step with modern values.

Many people gathered outside the palace compound hours before the ceremony despite unseasonably wet and cold weather, and even though they were not allowed to look inside.

“We came because today is the last day of (the emperor’s era of) Heisei, and we feel nostalgic,” said Akemi Yamauchi, 55, standing outside the palace with her husband.

“We like the current emperor. He has worked hard for the people, he is very thoughtful, and kind to everyone,” said her husband, Kaname. The couple came from Kyoto, Japan’s ancient capital, where emperors lived until about 150 years ago.

Messages have come from global leaders.

South Korean President Moon Jae-in expressed gratitude in a letter to Akihito for his emphasis on peace and contributions to developing relations between Seoul and Tokyo. US President Donald Trump expressed appreciation for his contribution to the two countries’ close relations. Trump had a courtesy meeting with Akihito during his 2017 Japan visit and will be the first foreign leader in May to meet the new emperor.

Japanese television talk shows displayed a countdown to the midnight transition, and programming was dominated by the abdication and looking back at major events in Akihito’s era, including a massive 2011 tsunami, a deadly earthquake in Kobe in 1995, and the Tokyo subway nerve gas attack in 1995 that shook Japan’s sense of safety and confidence.

Security was extremely tight around the palace and across downtown Tokyo, with thousands of police mobilized. Police arrested a man Monday night on suspicion of placing a pair of kitchen knives last week on the school desk used by Akihito’s grandson.

Still, Japan was in a festive mood over a change in an imperial era not caused by death. Many people visited shrines and temples to receive stamps dated on the last day of Akihito’s era of Heisei, or “achieving peace.” Some amusement parks and shops offered free admission and special deals, while customers had their last Heisei meals at restaurants. Naruhito’s era of Reiwa, or “beautiful harmony,” begins Wednesday.

“The emperor has finished his duties and he is passing the baton to the crown prince, so it’s time for celebration,” said Mitsuhiro Sugita, a 67-year-old green tea maker.

Akihito, 85, took the throne in 1989 and devoted his career to making amends for a war fought in his father’s name while bringing the aloof monarchy closer to the people.

With his common-born wife, Empress Michiko, he reached out to the people, especially those who faced handicaps and discrimination, as well as those hit by disasters, illuminating the hardships of people often overlooked by society.

Akihito was the first emperor to marry a commoner, one of many changes he brought to the palace. The couple also chose to raise their three children instead of leaving them with palace staff, and decided to be cremated upon their deaths in a smaller tomb side by side, also a tradition-breaking step.

Jeff Kingston, Asian studies director at Temple University’s Japan campus, says Akihito has served as Japan’s “chief emissary of reconciliation,” while acting as “consoler in chief” in reaching out to the people. Akihito was also a “strong advocate of the vulnerable and the marginalized in the Japanese society,” he said. “I think the people really warmed to him and felt that the monarchy was relevant to their lives because of these efforts by Akihito.”

Recent media surveys have shown public support for the imperial family at 80 percent, the highest ever for the institution.

Such respect did not come overnight. Akihito grew up during World War II and was 11 when his father, Hirohito, announced the end of the war on radio. Akihito embraced his role as peacemaker and often represented his father on reconciliatory missions as a young crown prince, decades before he became the emperor himself.

He is the first emperor in Japan’s modern history whose era did not have a war. Though he has avoided outright apologies, he has stepped up his expressions of regret in carefully scripted statements on the war.

Akihito visited China in 1992 and offered what was considered the strongest expression of regret over the war. He also visited the Philippines and other Pacific islands conquered by Japan that were devastated in fierce fighting as the US-led allies took them back.

That leaves his son Naruhito — the first emperor born after World War II — largely free of the burden of the wartime legacy, allowing him to seek his own role. Naruhito has said he would largely emulate his father’s pacifist stance and compassion for the people, but also said he hopes to seek a role of his own, possibly in issues related to water, which he studied at Oxford University in the early 1980s. That, or disaster resilience, or the environment, could appeal more to a people predominantly from postwar generations.

Akihito will be known as the emperor emeritus and will no longer have official duties. He won’t even attend his son’s succession rituals so as not to interfere with the serving emperor.

Akihito is expected to enjoy his retirement, going to museums and concerts, or spending time on his goby research at a seaside imperial villa. Akihito and Michiko will move to a temporary royal residence before eventually switching places with Naruhito.