US President Barack Obama has called on Vietnam to allow greater freedoms for its citizens.
Mr Obama argued that better human rights would improve the communist country's economy, stability and regional power.
On his second full day in the south-east Asian nation, Mr Obama also met with activists and entrepreneurs as part of a push for closer ties with the fast-growing, strategically crucial country. The visit included the lifting of a half-century-old arms sale embargo.
In a speech at the National Convention Centre, Mr Obama sought to balance the need for a stronger relationship with Vietnam with efforts to hold its leadership to account over what activists call an abysmal treatment of government critics.
He said nations are more successful when people can freely express themselves, assemble without harassment and access the internet and social media.
"Upholding these rights is not a threat to stability but actually reinforces stability and is the foundation of progress," Mr Obama told the audience of more than 2,000, including government officials and students from five universities across the Hanoi area.
"Vietnam will do it differently than the United States does ... But there are these basic principles that I think we all have to try to work on and improve."
Freedom of expression is where new ideas happen, Mr Obama said. "That's how a Facebook starts. That's how some of our greatest companies began."
Journalists and bloggers can "shine a light on injustice or abuse" when they are allowed to operate free of government interference or intimidation, he added.
And, stability is encouraged when voters get to choose their leaders in free and fair elections "because citizens know that their voices count and that peaceful change is possible. And it brings new people into the system," he continued.
Mr Obama also traced the transformation of the US-Vietnamese relationship, from wartime enemies to cooperation. He said the governments are working more closely together than ever before on a range of issues.
"Now we can say something that was once unimaginable: Today, Vietnam and the Unites States are partners," he said, adding that their experience was teaching the world that "hearts can change".
Earlier, Mr Obama met with six activists, including a pastor and advocates for the disabled and sexual minorities. He said several others were prevented from coming. "Vietnam has made remarkable strides in many ways," Mr Obama said, but "there are still areas of significant concern".
Mr Obama also referred in the speech to China's growing aggression in the region, something that worries many in Vietnam, which has territorial disputes in the South China Sea with Beijing.
Mr Obama received a round of applause when he declared that "big nations should not bully smaller ones", an allusion to China's attempt to push its rivals out of disputed territory. He said the United States will continue to freely navigate the region and support the right of other countries to do the same.
After Hanoi, Mr Obama flew to Ho Chi Minh City, formerly Saigon. He visited the Jade Emperor Pagoda, considered one of the most beautiful pagodas in southern Vietnam and a repository of religious documents that includes more than 300 statues and other relics. A strong smell of incense hung in the air as visitors frequently burn incense outside the main temple to announce to the heavens their arrival.
As Mr Obama paused before one statue, a guide explained that if he wanted to have a son, he should pray to her.
"I like daughters," he replied.
Shifting from the historical to the modern, Mr Obama also visited the Dreamplex business complex in Ho Chi Minh City, a space for start-up entrepreneurs that fits with Mr Obama's message about the potential benefits of closer ties to Vietnam's growing economy and its burgeoning middle class.
Mr Obama visited with several entrepreneurs, learning about a virtual game that helps people recover from nerve injuries and a smartphone that can serve as a laser cutter. But Mr Obama cautioned that you have to "be careful where you point it".
The meeting gave him another chance to promote the benefits of what he says will be enhanced trade under a 12-nation trade deal that is stalled in Congress and opposed by the leading US presidential candidates.
He said the pact, if approved, will accelerate economic reforms in Vietnam, boost its economic competitiveness, open up new markets and improve labour and environmental standards.
During his address, he said the agreement would give Vietnamese workers the right to form labour unions and would prohibit forced and child labour. He also predicted it would lead to greater regional cooperation.
"Vietnam will be less dependent on any one trading partner and enjoy broader ties with more partners, including the United States," Mr Obama said.