Saudi King Salman decorated President Trump with the gold King Abdulaziz medal during a meeting at the royal court in the Saudi capital on May 20. (Reuters)

On his first trip abroad as president, Donald Trump received the warmest of welcomes.

Massive images of Trump and King Salman bin Abdul Aziz were projected on the facade of the Ritz Carlton in Riyadh.

Jets were flown in Trump's honor. Men carrying American and Saudi Arabian flags rode on horses as they accompanied the presidential limousine. A military band played as Trump and his wife, Melania, got out of the car and walked on the red carpet to greet the Saudi king.

But Trump has not always been a fan of the conservative Muslim nation.

Before he was leader of the free world, Trump spent years publicly bashing Saudi Arabia. He repeatedly demanded that the Saudis compensate the United States for its long-standing alliance. During the presidential election, he condemned the country for its history of human rights violations. (As president, he has praised authoritarian leaders and has signaled that addressing abuses in other countries will not be at the forefront of his administration.)

“They must pay dearly! NO FREEBIES,” he tweeted in March 2015, saying Saudi Arabia should use its vast wealth to pay the United States accordingly for its “help and protection.”

Trump repeated his criticisms multiple times as a Republican presidential candidate. He did so during an interview with NBC's Chuck Todd on “Meet the Press” in August 2015, at a speech in Green Bay, Wis., in August 2016 and during the presidential debate in Hempstead, N.Y., in September 2016.

He also was a critic of President Barack Obama's policies in the Middle East.

In 2015, he criticized first lady Michelle Obama for not wearing a scarf during a visit, saying the Saudis “were insulted.” During this trip, Melania Trump's hair also was uncovered.

Trump also used Saudi Arabia to attack his opponent, former Democratic presidential candidate Hillary Clinton.

Last year, Trump slammed the Clinton Foundation for accepting millions of dollars from a country that abuses women and is intolerant of members of the lesbian, gay, bisexual and transgender community.

“You talk about women and women's rights. These are people that push gays off business — off buildings. These are people that kill women and treat women horribly, and yet you take their money,” Trump said during a presidential debate last October in Las Vegas. “So I'd like to ask you right now. Why don't you give back the money that you've taken from certain countries that treat certain groups of people so horribly? Why don't you give back the money. I think it would be a great gesture …”

Crooked Hillary says we must call on Saudi Arabia and other countries to stop funding hate. I am calling on her to immediately return the $25 million plus she got from them for the Clinton Foundation!

Posted by Donald J. Trump on Monday, June 13, 2016

According to the foundation's donor list, it received between $10 million and $25 million from Saudi Arabia. A spokesman for the foundation has said that the money was not given while Clinton was secretary of state.

Now, Trump has switched from being a loud critic of Saudi Arabia to a friendly ally.

Although he campaigned against Muslims during the election — proclaiming that “Islam hates us” — he comes to Saudi Arabia with a speech preaching religious tolerance.

The Saudi leader also gave the president the highest of honor for a foreign dignitary, the collar of Abdulaziz al-Saud, named for the kingdom’s founder, which Salman hung on a thick gold chain around Trump’s neck.

One of the highlights of Trump's visit is a multibillion-dollar deal to modernize Saudi Arabia's military and cyber defense systems, as well as its airborne intelligence capabilities. The two leaders signed a letter of intent to “support Saudi Arabia's defense needs” and agreements for almost $110 billion in military purchases from the United States. These include naval ships, tanks and other military vehicles that were subject to agreements under previous administrations.

The relationship between the United States and Saudi Arabia was strained under Obama, whom the kingdom criticized for being too soft on Iran and for failing to push for the ouster of Syrian President Bashar al-Assad. Still, Obama also faced pressure from human rights groups over Saudi Arabia's history with abuses and repression.

Philip Rucker, Karen DeYoung and Abby Phillip contributed to this story.

READ MORE:

Trump gave a thumbs-up in Saudi Arabia, which the U.S. Embassy says is ‘rude.’ But it’s not really.

U.S. first lady ignores Trump criticism and shuns headscarf

The surreal strangeness of Trump’s trip to Saudi Arabia