A message for peace and harmony, featuring a mythical Korean "turtle" representing longevity, set the theme as the curtain fell at the closing ceremony of the Pyeongchang Winter Olympics on Sunday.

Athletes from the over 90 countries competing in 102 medal events across seven sports and 15 disciplines entered Pyeongchang Olympic Stadium in loosely formed groups, some waving small flags representing their countries and carrying selfie sticks, before taking seats reserved for them in the stands.

Nao Kodaira, the gold medal winner in the women's 500 meters and silver medalist in the women's 1,000, was flagbearer for Japan.

Pyeongchang Mayor Sim Jae Guk passed the Olympic flag to International Olympic Committee President Thomas Bach, who handed it over to Beijing Mayor Chen Jining.

"Over the past 17 days, we have experienced Olympic Games rooted in tradition and showing the way to the future. They have proved true the words of our founder, Pierre de Coubertin, when he said the Olympic Games are a homage to the past and an act of faith in the future," Bach, who declared the games closed, said in his speech. "To our gracious hosts, the people of Korea, I say: thank you."

South Korean President Moon Jae In had held talks with Kim Yong Chol, head of the North Korean ruling party's United Front, hours before attending the event with Kim, who arrived earlier in the day in South Korea as chief of a high-ranking North Korean delegation to the closing ceremony.

Protesters demonstrated against the visit by the suspected culprit behind deadly attacks on the South.

U.S. President Donald Trump's daughter and adviser Ivanka Trump, who also met with Moon earlier in the day and urged putting "maximum pressure" against the North over its missile and nuclear ambitions, also attended the closing ceremony, making for a striking tableau as the group waved to the crowd from high above in the arena.

"William Shakespeare once said, in Romeo and Juliet, 'Parting is such sweet sorrow.' Even though we are now saying goodbye to each other, Pyeongchang 2018 will be long remembered with beautiful and unforgettable memories," said Pyeongchang Olympic organizing committee President Lee Hee Beom.

After a countdown affirming a "Dream for Tomorrow" and the raising of the South Korean national flag and singing of its national anthem, teenage prodigy Yang Tae Hwan played his electric guitar from the highest point in the stadium while a solo dancer performed the traditional "Spring Dance of Nightingale" below.

The turtle formed by a group of illuminated puppeteers traveled in a funeral procession in memoriam of elite athletes who have passed away to the center of the stadium where it separated, embarking on another journey to convey the memories of the games.

In the segment dubbed "The Next Wave," 40 dancers did a combination of modern dance and new media art, representing a break from convention as the Olympic movement sets its sights on Beijing.

K-pop singer CL took to the stage for her song "The Baddest Female" and also sang 2NE1's hit song "I Am the Best" with a group of 20 professional dancers who carried torches.

After the Olympic flame was extinguished, the final segment to music composed by music director Yang Bang Ean -- an ethnic Korean who grew up in Japan -- featured a cast of about 480 members.

DJ Raiden then pumped his electronic dance music as the athletes, holding LED balls, joined in the closing celebration.