RIO DE JANEIRO – Immersing himself in Brazil’s poverty and pride, President Obama on Sunday held up the South American nation as a model of democratic change in a time of uprisings and crackdowns across the Arab world and yet another war front for the United States.

From Rio’s glamorous beaches to a notorious slum, he glimpsed the city’s cultural extremes and offered the kind of personal engagement that can pay political dividends for years. Less than one day after announcing U.S. military strikes against Libya’s government, Obama made time to kick a soccer ball around with kids in a shantytown.

The competing stories of Obama’s itinerary — a war front in Africa, an economic commitment to South America — divided his time in incongruous ways. By morning, he spoke with his security team about the international assault against Moammar Gadhafi’s defenses; by night, he was to stand atop a mountain and admire Rio’s world-famous statue of Jesus.

Meanwhile, U.S. warplanes pounded faraway Libya.

It was all summed up by one image: Obama, adeptly juggling a soccer ball, as his aides helped him juggle his agenda.

In a speech, Obama celebrated Brazil as a place that has shifted from dictatorship to democracy, moving millions into its middle class and embracing human rights. He underlined that point as unrest sweeps the Middle East and north Africa, leading to dramatic change in some cases and violent crisis in Libya.

“As two nations who have struggled over many generations to perfect our own democracies, the United States and Brazil know that the future of the Arab world will be determined by its people,” Obama told an invitation-only crowd inside an ornate hall here.

“No one can say for certain how this change will end, but I do know that change is not something that we should fear,” he said. “When young people insist that the currents of history are on the move, the burdens of the past are washed away.”

His trip to this region has been overshadowed by the onset of war in Libya. Obama has tried to show command of the war strategy without either altering his diplomatic mission or offending his hosts in Latin America.

And Sunday, he was determined to spend time with his family, be among the people and feel the culture.

Obama and his family visited the City of God shantytown that gained fame through a movie of the same name. The slum is undergoing a transformation as Rio works to improve the plight of its poorest people and clean up its reputation ahead of hosting the 2016 summer Olympics.

Obama, his wife, Michelle, and their daughters, Malia and Sasha, watched children pound on drums and perform a dazzling acrobatic dance. And then all the Obamas took turns at a little soccer, led by the president.

Obama chose a community center in the heart of one of more than 1,000 slums, or “favelas,” surrounding the city. The tour was designed to illustrate Obama’s push for what officials call citizen security, an emerging concern in Latin American countries as they wrestle with narco-crime and poverty.

Dozens of young children pressed up against a chain-link fence trying to get a look at Obama; he ultimately stepped outside and gave a big wave.

The president’s route to the slum was itself presented a contrast. Obama began and ended his day in a hotel that fronted the famed Copacabana beach, where tourists and locals in bathing suits soaked in the sun.

“He is thinking of Rio as more than just the Christ and Copacabana,” said Noemia Marinho, a 40-year-old lingerie saleswoman who lives in the slum. “Maybe our government will look to us more as well.”

Obama’s tour had an underlying goal of endearing him to a multicultural country where his personal story already makes him popular. He is trying to bolster ties to Brazil — and do the same in Chile and El Salvador over the next three days — as a way to boost U.S. economic, security and political interests.

The president delivered his speech at the Theatro Municipal performance hall. Here, once again, Obama made a game effort to connect to the locals. That included making a solid effort at speaking some Portuguese, drawing some cheers.

He thanked those present for showing up even though a soccer match between two of Rio’s biggest rival teams, Vasco and Botafogo, would begin a few hours after his speech. The very mention of the match in soccer-obsessed Brazil provoked a strong reaction from the fans of the teams in the audience.

“For so long, you were called a country of the future, told to wait for a better day that was always just around the corner,” Obama said. “Meus amigos, that day has finally come.”

The speech was originally billed as an outdoor event open to all, but U.S. officials decided at the last minute to move inside as logistics, costs and other concerns mounted. That sharply reduced the ability of many people to see him.