While the world was watching America's gay rights transformation, the Obama administration was pursuing a quieter mission to export the same freedoms overseas to places like sub-Saharan Africa, Latin America and eastern Europe.

President Barack Obama speaks during a reception in recognition of LGBT Pride Month in the East Room of the White House in Washington, Thursday, June 9, 2016. Susan Walsh / AP

The U.S. has deployed its diplomats and spent tens of millions of dollars to try to block anti-gay laws, punish countries that enacted them, and tie financial assistance to respect for LGBTQ rights. It was a mission animated in part by former Secretary of State Hillary Clinton's declaration that "gay rights are human rights."

Yet the U.S. encountered occasional backlash, including from some rights groups that said public pressure by the West made things worse.

"I walked into a very backward environment in 2009," said Susan Rice, President Barack Obama's national security adviser and former U.N. ambassador. In an Associated Press interview, Rice said both the U.N. and U.S. had avoided taking on the issue.

She argued that despite a cascade of pressing global crises, the White House had tried to "deal with the urgent and deal with the important, and even if the important is, some might say, optional, it's important."

In its latest push to use dollars as leverage, the Obama administration announced Wednesday it is enacting a rule prohibiting U.S. Agency for International Development contracts from going to groups that discriminate in delivery of services. That means a clinic, food program or shelter can't refuse services to a gay or transgender person.

Yet even in countries where legal protections have improved, like Brazil and Argentina, it's difficult to draw a straight line between U.S. advocacy and progress, and in Latin America, those changes have been accompanied by increasing violence against LGBTQ people. In Uganda, a court eventually invalidated an anti-gay law the U.S. had emphatically opposed. But in Gambia, anti-gay rhetoric has escalated despite a U.S. decision to revoke the country's preferential trade status following an LGBTQ crackdown.

The Morning Rundown Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

The growing focus on gay rights in diplomacy mirrored the shift in attitudes in the U.S. toward LGBTQ people, illustrated by seismic changes like gay marriage and gays serving openly in the military. As with its domestic efforts, the Obama administration faced objections from social conservatives and some religious groups at home and abroad who called it an inappropriate use of government to infringe on others' cultural beliefs.

RELATED: Air Force Cadets Describe Life After 'Don't Ask, Don't Tell'

A 2011 memorandum signed by Obama directed the government for the first time to use diplomacy and foreign aid to "promote and protect the human rights of LGBT persons." U.S. embassies started taking part in pride celebrations, with outposts in socially liberal capitals like Tel Aviv and London raising rainbow flags.

US Secretary of State Hillary Clinton addresses the assembly during a speech entitled "Free and Equal in Dignity and Rights" at the United Nations in Geneva on December 6, 2011, ahead of the International Human Rights Day. Sebastien Feval / AFP - Getty Images

A speech by Clinton to the U.N. in Geneva that year thrust the issue to the forefront, at least for a moment, when she said that "gay rights are human rights, and human rights are gay rights," in an echo of her famous 1995 speech in Beijing equating women's rights and human rights. Mira Patel, a former State Department adviser now working on Clinton's presidential campaign, said she was shocked when the secretary first used the line publicly at a pride reception for U.S. diplomats.

"I never expected these issues could be elevated so fast and at such a high level," Patel said.

The U.S. in 2010 started issuing passports to transgender people that reflected their current gender identity, and the White House started sending openly gay athletes as part of its delegation to Olympics ceremonies — including the 2014 Winter Games in Russia. At the United Nations, Rice and other diplomats secured language in several resolutions opposing discrimination or condemning extrajudicial killings of LGBTQ people.

For Obama, who only came around to fully embracing gay rights while in office, the campaign came to a head last year in Nairobi, Kenya. Warned in no uncertain terms ahead of his visits to keep quiet about gay rights, Obama called for equal legal treatment for gays while standing next to President Uhuru Kenyatta, who brushed it off and insisted it was "not really an issue."

Bisi Alimi, a Nigerian gay rights activist, said that advocacy was critical to helping dissolve what for many Africans has been a persuasive argument against gay rights: that the U.S. and other rich nations are engaging in paternalism and cultural colonialism.

"We should not forget that Obama's father is Kenyan," Alimi said by phone from London, where he fled after being physically attacked in Nigeria. "There was no better place for him to say that than in a place where his nationality wouldn't be questioned, where he wouldn't be seen as a Westerner telling us how to live our lives."

Yet not infrequently, LGBTQ activists in other countries have urged the U.S. to pull back — or at least to stop making the case publicly.

In Uganda, the U.S. in 2014 cut off visas for senior Ugandan officials, canceled aid and nixed a joint military exercise to punish Uganda for legislation that became known as the "Kill the Gays" bill. But activists said heavy-handed U.S. advocacy had given gay rights opponents the evidence they needed to argue that a native rights movement was being orchestrated by Washington.

RELATED: Coming Out Still a 'Life and Death' Decision in Many Countries

Two years earlier, stolen diplomatic cables released by WikiLeaks showed Ugandan activists had insisted to U.S. diplomats that "they preferred quiet diplomacy — not public statements."

"What we've seen in the last eight years has been 99 percent great and 1 percent horrible backlash," said Jay Michaelson, an American author and LGBTQ activist who's written extensively on the subject.

Rice said the key was to tailor efforts to each country's circumstances, limiting advocacy to behind-the-scenes meetings when a public push might cause more harm.

"What we don't want to do to the extent we can avoid it is expose individuals who aren't wanting to be exposed and to put individuals at risk," Rice said.

Follow NBC OUT on Twitter, Facebook and Instagram.