HO CHI MINH CITY, Vietnam (AP) — Wrapping up a historic visit to Vietnam, U.S. President Barack Obama on Wednesday praised the country’s next generation of leaders for being more conscious of the environment than previous generations and urged them to “do something about” climate change.

During his final public event here, Obama basked in the admiration of hundreds of young leaders who participated in a town hall-style event and prefaced some of their questions to him with praise about his leadership and his “inspiring speeches.”

Obama used a question about preserving a Vietnamese cave from development to pivot to climate change, one of his top issues as president. He said Vietnam will be one of the countries most affected by the trend of warming temperatures and rising seas.

“That could have a huge impact on Vietnam’s ability to feed its people, on fishermen, on farmers, and it could be a really big problem if we don’t do something about it, so it’s going to be up to you to start,” said Obama, who routinely includes question-and-answer sessions with young leaders on his foreign trips.

“One of the great things about your generation is that you’re already much more conscious about the environment than my generation was or previous generations were,” said Obama. He told a previous questioner that he “fooled around a lot” and wasn’t serious about school when he was young.

“I was more into basketball and girls. I wasn’t always that serious,” Obama said. “You’re already way ahead of me. That’s good.”

Obama also promoted a 12-nation, trans-Pacific trade pact that includes Vietnam but is stalled in the U.S. Congress and opposed by the three leading U.S. presidential candidates. But he avoided wading too deeply into politics when asked where he sees himself and the world in five years, around the end of his successor’s first term. Obama has said on previous occasions that world leaders ask him all the time about the unpredictable election.

“Sometimes, our politics doesn’t express all the goodness of the people, but usually, eventually, the voters make good decisions and democracy works,” Obama said. “So I’m optimistic that we’ll get through this period.”

As for his future, Obama said he expects to stay involved with public policy issues and return to his roots as an organizer. “I’ll be like a community organizer, except a little more famous than I used to be.”

The town-hall event capped Obama’s historic visit to Vietnam. He spent three days in the capital of Hanoi, in the north, and in Ho Chi Minh City, in the south, meeting with government leaders and addressing the Vietnamese people in a speech and through less formal encounters, such as when he worked out in the hotel gym Wednesday morning and “people were trying to take selfies” with him.

In a move symbolizing how deeply relations between the former wartime enemies had thawed, Obama announced the end of a five-decades-old ban on the sale of arms to Vietnam. He also announced that the Peace Corps would begin operating in the country for the first time.

In his appearances, Obama also pressed Vietnam to allow greater freedoms for its citizens, arguing that respect for human rights would improve the communist country’s economy, stability and regional power. He returned to the issue Wednesday when a young Vietnamese woman asked about the importance of governments promoting the arts and culture.

“You’ve got to let people express themselves. That’s part of what a modern 21st century culture is all about,” Obama said.

Before the event, Obama met privately at the U.S. Consulate with staff and family members. The White House said the meeting included seven Foreign Service nationals who served at the U.S. Embassy during the evacuation of Saigon — the former name for Ho Chi Minh City — in 1975 during the Vietnam War.

Japan was the next and final stop on Obama’s swing through Asia, a region he says helped shape him growing up in his native Hawaii and later in Indonesia. Obama was attending a summit of the Group of Seven industrialized nations starting Thursday. He also planned a historic visit Friday to Hiroshima, seven decades after the U.S. ushered in the nuclear age by dropping an atomic bomb to end World War II. Obama will be the first sitting U.S. president to visit Hiroshima.

He planned to meet with Japanese Prime Minister Shinzo Abe after arriving late Wednesday.

Japanese Chief Cabinet Secretary Yoshihide Suga said Abe would raise the recent arrest of a former U.S. Marine in connection with the murder of a Japanese woman on the southern island of Okinawa.

___

Associated Press writers Darlene Superville in Washington and Mari Yamaguchi in Ise, Japan, contributed to this report.