TOKYO — Everyone knew that Shinzo Abe, the prime minister of Japan, was headed to Rio to represent the country that will host the 2020 Summer Olympics. But viewers who tuned into the broadcast of Rio’s closing ceremony on Monday morning Japan time were surprised to see their normally sober leader pop out of an oversize green drainpipe dressed as Super Mario, the star of the popular Nintendo video game series.

Mr. Abe’s appearance followed a glossy promotional video showing athletes in stereotypical scenes from Tokyo, as well as various characters from popular culture, including Hello Kitty and Doraemon. The scene cut to Mr. Abe in a Toyota Century, fretting that he wouldn’t make it to Rio on time, followed by an animated Super Mario diving into a green pipe in Tokyo, emerging as a human figure from the green pipe on the field in Rio de Janeiro. When his costume fell off, the prime minister emerged, holding a red ball and waving a red cap, a shadow of a smile on his face.

Reaction on social media in Japan was swift and amused, with “Abe Mario” the top trending topic on Twitter.