Donald Trump was in his element, mingling with beauty pageant contestants and business tycoons as he brought his Miss Universe pageant to Russia for a much-anticipated Moscow debut. Nonetheless, Trump was especially eager for the presence of another honored guest: Russian President Vladimir Putin.

Trump tweeted Putin a personal invitation to attend the pageant, and a one-on-one meeting between the New York businessman and the Russian leader was scheduled for the day before the show.

Putin canceled at the last minute, but he sent a decorative lacquered box, a traditional Russian gift, and a warm note, according to Aras Agalarov, a Moscow billionaire who served as a liaison between Trump and the Russian leader.

Still, the weekend was fruitful for Trump. He received a portion of the $14 million paid by Agalarov and other investors to bring the pageant to Moscow. Agalarov said he and Trump signed an agreement to build a Trump Tower in the heart of Moscow — at least Trump’s fifth attempt at such a venture. And Trump seemed energized by his interactions with Russia’s financial elite at the pageant and a glitzy after-party in a Moscow nightclub.

“Almost all of the oligarchs were in the room,” Trump bragged to Real Estate Weekly upon returning home.

Miss Universe 2013 Gabriela Isler of Venezuela and pageant owner Donald Trump point at each other while posing for a photograph after the Miss Universe pageant in Moscow on Nov. 9, 2013. (Ivan Sekretarev/AP)

Trump’s relationship with Putin and his warm views toward Russia, which began in the 1980s when the country was still part of the Soviet Union, have emerged as one of the more curious aspects of his presidential campaign.

The overwhelming consensus among American political and national security leaders has held that Putin is a pariah who disregards human rights and has violated international norms in seeking to regain influence and territory in the former Soviet bloc. In 2012, one year before Trump brought his beauty pageant to Moscow, then-Republican presidential nominee Mitt Romney called Russia the United States’ top geopolitical threat — an assessment that has only gained currency since then.

Trump has conveyed a different view, informed in part through his business ambitions. Since the 1980s, Trump and his family members have made numerous trips to Moscow in search of business opportunities, and they have relied on Russian investors to buy their properties around the world.

“Russians make up a pretty disproportionate cross-section of a lot of our assets,” Trump’s son, Donald Jr., told a real estate conference in 2008, according to an account posted on the website of eTurboNews, a trade publication. “We see a lot of money pouring in from Russia.”

The dynamic illustrates the extent to which Trump’s worldview has been formed through the lens of commerce rather than the think tanks, government deliberations and international diplomatic conferences that typically shape the foreign policy positions of presidential candidates.

It also reflects Trump’s willingness to see world leaders through his own personal connections. In a Republican Party in which an ability to stand up to Putin has been seen as a test of toughness, Trump’s relationship with the Russian leader is instead one of mutual flattery. Putin said in December that Trump was a “colorful and talented” person, a compliment that Trump said at the time was an “honor.”

The back-and-forth has continued. In a mid-June rally, Trump cited those comments as the reason he will not reject the Russian leader. “A guy calls me a genius, and I’m going to renounce?” Trump said. “I’m not going to renounce him.” The next day in St. Petersburg, Putin again called Trump a “colorful person” and said he welcomed Trump’s proposal for a “full-scale resumption” of U.S.-Russia ties.

On the campaign trail, Trump has called for a new partnership with Moscow, overhauling NATO, the allied military force seen as the chief protector of pro-Western nations near Russia. And Trump has surrounded himself with a team of advisers who have had financial ties to Russia.

This account of Trump’s 30-year history of business with Russia — and that of his advisers — is based on interviews as well as a review of deposition transcripts and other court records in which Trump and his associates have discussed their overseas work. Trump declined to be interviewed for this article, as did top campaign aides and most members of his foreign policy team. The Kremlin also declined to comment about Trump’s visit to Moscow.

The coming together of Trump’s business and political agendas was evident during his 2013 Moscow trip, in which he was seeking deals at the same time he was starting to ponder a presidential run.

Agalarov and his son, Russian pop musician Emin Agalarov, told The Washington Post that they befriended Trump after the pageant and listened as he described his views of U.S.-Russia relations.

“He kept saying, ‘Every time there is friction between United States and Russia, it’s bad for both countries. For the people to benefit, this should be fixed. We should be friends,’ ” Emin Agalarov recalled.

Russia has signaled a deep interest in the U.S. election and in Trump, in particular. The Russian ambassador to the United States, breaking from a tradition in which diplomats steer clear of domestic politics, attended Trump’s April foreign policy speech in which he called for ending “this horrible cycle of hostility” between the two nations.

And in the past week, The Post reported that hackers tied to the Russian government had gained access to the Democratic National Committee’s opposition research file on Trump.

A spokesman for the Russian Embassy said that Ambassador Sergey I. Kislyak’s attendance at the Trump speech should not be considered an indication that Russia is partial to Trump. “There is no preference,” the spokesman said.

Still, the relationship is setting off alarms in pro-Western capitals — and in the U.S. foreign policy community.

Trump’s campaign rhetoric is the “biggest dream of everyone in the Kremlin,” Tina Khidasheli, defense minister of Georgia, a U.S. ally, told The Post. “It’s scary, it’s dangerous, and it’s irresponsible.”

Her view is shared in the United States by leading Russia experts from both political parties.

Michael McFaul, who stepped down in 2014 as the U.S. ambassador to Russia, said Trump’s stance toward Russia “makes everyone I talk to around the world nervous — and it makes me nervous.”

David J. Kramer, who served as deputy assistant secretary of state dealing with Russia during the George W. Bush administration, said he was “appalled” by Trump’s approach.

Trump’s spokeswoman did not respond to detailed written questions.

One of his foreign policy advisers, retired Lt. Gen. Michael Flynn, who headed the Defense Intelligence Agency in the Obama administration, said Trump would be “exceedingly stronger” than Hillary Clinton, the presumptive Democratic presidential nominee, who he said was an “utter failure” in her goal as secretary of state to “reset” U.S.-Russia relations.

Trump has long aspired to build a Trump Tower in Russia — a market that first gained his attention in the 1980s as the Cold War was ending and the Soviet Union began to open more to outsiders.

“Russia is one of the hottest places in the world for investment,” Trump said in a 2007 deposition. “We will be in Moscow at some point,” he promised.

Part of the allure was what Trump and his associates saw as a huge opportunity — the chance to market American-style luxury apartments to the wealthy elite in a place that still mostly offered utilitarian Soviet-style construction.

The Russian market had “natural strength, especially in the high-end sector,” said Donald Trump Jr. in his 2008 real estate conference speech. Moscow held special appeal because wealthy people throughout the region wanted to own real estate in the capital city, he said.

Trump’s 1987 trip represented his first public exploration of business prospects in Moscow. He went with his then-wife, ­Ivana, to scope out sites for luxury hotels he hoped to build in a joint venture with the Kremlin’s hotel and tourism agency, according to Trump’s memoir, “The Art of the Deal,” which was published the same year.

The project never got off the ground — an outcome that would repeat itself multiple times between then and his 2013 trip.

In 1996, Trump tried to partner with U.S. tobacco executives to build a luxury condominium complex in Moscow. Ted Liebman, an architect who worked with Trump, recalled drawing sketches of the proposed Trump International for the businessman to use in meetings with Moscow officials.

In 2005, Trump signed a one-year deal with a New York development company to explore a Trump Tower in Moscow. Bayrock Group found a site — an old pencil factory — but the effort fizzled again.

Trump claimed in a later court proceeding that Russian investors were spooked when a 2005 book questioned his net worth.

But the Russia quest continued. In his 2008 speech, Donald Jr. announced that he had traveled to Russia six times in the previous 18 months. But, he said, Russia presented enormous challenges.

“As much as we want to take our business over there, Russia is just a different world,” the younger Trump said. “It is a question of who knows who, whose brother is paying off who. . . . It really is a scary place.”

The elder Trump’s business ambitions have extended throughout the former Soviet Union and the Eastern bloc. He has explored deals in Kiev, Yalta and Warsaw and licensed his name for the construction of a five-star hotel in Baku, Azerbaijan, which has been mostly built but is not yet open.

As Trump looked for deals in Russia, Russian consumers became a key market for his real estate projects in the United States and elsewhere.

Trump’s partners on a Panama project traveled to Moscow in 2006 to sell condos to Russian investors, according to litigation filed in Florida. Trump also sold a mansion in Palm Beach in 2008 for $95 million to Russian oligarch Dmitry Rybolovlev, according to property records. Trump had purchased the mansion at a bankruptcy auction less than four years earlier for $41.4 million, records show.

In 2013, Trump found a new Russian partner for a Moscow real estate project, Aras Agalarov, an Azeri-born real estate developer who is sometimes called the “Trump of Russia” for his tendency to emblazon his name on his development projects.

The Agalarovs are wealthy developers who have received several contracts for state-funded construction projects, a sign of their closeness to the Putin government. Shortly after the pageant, Putin awarded the elder Agalarov the “Order of Honor of the Russian Federation,” a prestigious designation.

Agalarov and his son Emin spoke with The Post earlier this year at the chic Nobu restaurant inside Crocus City Mall, their gleaming luxury development.

They said they first met Trump after hiring Miss Universe contestants for one of Emin’s music videos. Trump ultimately appeared in the video along with the beauty queens. After the video and the 2013 pageant, the Agalarovs said they developed a deeper relationship with Trump.

“I convinced my father it would be cool to have next to each other the Trump Tower and Agalarov Tower, and he was kind of into it at some point,” Emin Agalarov said.

The Trump Tower deal never moved past preliminary discussions. But Agalarov said the family is interested in a possible future venture.

Trump’s top aides, too, have had ties to Russia. Campaign chairman Paul Manafort has done multimillion-dollar business deals with pro-Russian oligarchs and was a longtime adviser to the Russia-aligned Ukrainian president whose 2014 ouster triggered Russia’s intervention in Ukraine, a major source of tension between Russia and the United States as well as its NATO allies.

An adviser who helped run Trump’s efforts in the New York primary, Michael Caputo, lived in Russia in the 1990s. Caputo also had a contract for several months in 2000 with the Russian conglomerate Gazprom Media to improve Putin’s image in the United States.

Caputo declined to comment but told the Buffalo News, his hometown paper, that he was “not proud of the work today. But at the time, Putin wasn’t such a bad guy.”

Flynn, the former Defense Intelligence Agency chief who is advising Trump and has been mentioned as a possible ­vice-presidential running mate, stunned the diplomatic community by sitting near Putin at a 2015 Moscow dinner honoring RT, the English-language network aligned with the Kremlin that broadcasts into the United States.

Flynn said he spoke in Russia about how he thought Washington and Moscow should work more closely together, particularly in reining in Iran.

Carter Page, also a Trump foreign policy adviser, once ran the Moscow office of Merrill Lynch, including advising the Russian energy giant Gazprom, according to his biography posted on his employer’s website.

Page did not respond to questions from The Post. In an interview this year with Bloomberg News, he hinted that Trump’s election could be a boost for some of his Russian associates who have been hurt by U.S. sanctions imposed after Russia’s intervention in Ukraine. “There’s a lot of excitement in terms of the possibilities for creating a better situation,” Page told the news service.

The Agalarovs, too, expressed enthusiasm for what Trump has told them.

“He keeps underlining that he thinks President Putin is a strong leader,” Emin Agalarov said. “This could be an amazing breakthrough. If [Trump] becomes president and actually becomes friends with Putin, we would avoid 10 wars every year at least.”

Editor’s note: A previous version of this story said the Agalarovs’ fortune was built in part through state-funded construction projects; it has been updated to reflect the Agalarovs’ statement that they have yet to make money from contracts for state-funded projects.