US President Barack Obama has held up Indonesia as an example of how a developing nation can embrace democracy and diversity.
He was speaking in Jakarta on a visit to the world's largest Muslim nation.
Mr Obama said innocent people across the world were still targeted by militants but emphasised that the US was not at war with Islam.
Analysts say it is his biggest attempt to engage the Islamic world since a speech in Cairo last year.
Mr Obama was speaking at the University of Indonesia, before an audience of 6,000 people.
In his address, he touched on the four years he spent in the country as a child and emphasised the importance of Indonesia's example as a growing economy and a majority-Muslim nation that is largely tolerant of other religions.
"Today, I return to Indonesia as a friend, but also as a president who seeks a deep and enduring partnership between our two countries," he said.
"Because as vast and diverse countries; as neighbours on either side of the Pacific; and above all as democracies - the United States and Indonesia are bound together by shared interests and shared values."
He also highlighted the role religion had played in Indonesia's development, praising the country's spirituality and "rich diversity".
"Just as individuals are not defined solely by their faith, Indonesia is defined by more than its Muslim population," he said.
"But we also know that relations between the United States and Muslim communities have frayed over many years. As president, I have made it a priority to begin to repair these relations."
He said more work needed to be done to address "the issues that have caused tensions for many years" but appealed for unity to defeat "violent extremists".
"I have made it clear that America is not, and never will be, at war with Islam," he said.
"Instead, all of us must work together to defeat al-Qaeda and its affiliates, who have no claim to be leaders of any religion - certainly not a great, world religion like Islam. But those who want to build must not cede ground to terrorists who seek to destroy. This is not a task for America alone."
But among the kind words for his hosts, there was also a thinly-veiled swipe at China, says the BBC's Guy Delauney in Jakarta - in particular its treatment of political dissidents.
"Prosperity without freedom is just another form of poverty," Mr Obama said. "Because there are aspirations that human beings share - the liberty of knowing that your leader is accountable to you - and that you won't get locked up for disagreeing with them."
Mr Obama's trip to Asia covers four successful democracies - and shows the direction the US would like others to follow, our correspondent says.
The president also revisited some of the themes he raised in his June 2009 speech in Cairo: the conflicts in Iraq, Afghanistan and between Israel and the Palestinians.
In a reminder of the difficulties he faces on that last front, Israel decided to build more apartments for Jewish settlers in disputed East Jerusalem.
Peace talks between Israel and the Palestinians resumed in September after a break of almost two years but were suspended after a few weeks when a freeze on the building of Jewish settlements expired.
When Mr Obama delivered his Cairo speech he was riding a wave of goodwill, says the BBC's Middle East analyst Roger Hardy. But since then, the mood has changed. Recent polls show that in key parts of the Muslim world his credibility has slumped.
Mr Obama had earlier addressed many of the same themes in a wide-ranging news conference with President Susilo Bambang Yudhoyono.
The president's short trip has afforded him little leisure time, but before the university speech Mr Obama and his wife Michelle managed a visit to Jakarta's Istiqlal mosque, the largest in South-East Asia.
He has been forced to leave Indonesia about two hours early so his flight can outrun the volcanic ash cloud thrown up by the recent deadly eruption of Mount Merapi.
Indonesia is the second stop on his four-nation tour of Asia after India. The next stops are South Korea for the summit of G20 leaders and finally Japan.