RIYADH, Saudi Arabia — Saudi Arabia's King Salman appointed his 31-year-old son Mohammed bin Salman as crown prince on Wednesday, placing him first-in-line to the throne and laying the groundwork for an entirely new generation of royals to take the reins.

Saudi Arabia's once powerful counterterrorism czar, Prince Mohammed bin Nayef, was removed from the line of succession — giving the younger prince a firmer hold on the kingdom's foreign policies, including its close ties with U.S. President Donald Trump, its rivalry with Iran, its more than two-year-long war in Yemen and its punishing moves to isolate Qatar.

The appointment of such a young royal as the immediate heir to the throne essentially sets Saudi policy for decades in the hands of a man seen as a risk taker.

"He could be there for 50 years," said Kristian Coates Ulrichsen, a research fellow at the James A. Baker III Institute for Public Policy at Rice University. "If you look at it positively, it is basically setting Saudi Arabia's course into the 21st century."

The shuffle stripped Mohammed bin Nayef of his title as crown prince and interior minister, overseeing security. The announcements were made in a series of royal decrees carried on the state-run Saudi Press Agency.

The all-but-certain takeover of the throne by Mohammed bin Salman awards vast powers to a young prince who has taken a hard-line with Iran and who has led a war in Yemen that has killed thousands of civilians. Iran's state TV has called the appointment a "soft coup in Saudi Arabia."

The prince, known as MBS, already oversees a vast portfolio as defense minister. He has also become popular among some of Saudi Arabia's youth, who make up the bulk of the population, for pursuing reforms that have opened the deeply conservative country to entertainment and greater foreign investments as part of an effort to overhaul the economy, including plans to list a percentage of the state-run oil giant Saudi Aramco.

The young prince was little known to Saudis before Salman became king in January 2015. He had previously been in charge of his father's royal court when Salman was the crown prince.

The Saudi monarch quickly named him second-in-line to the throne two years ago to the surprise of many within the royal family who were older and more experienced.

MBS is now poised to become the first Saudi monarch from a generation of royals who represent the grandsons of the country's founder, King Abdul-Aziz. For decades, the throne has passed from elderly brother to elderly brother — all sons of the late founder.

The recasting of the line of succession marks the first real test of the ruling Al Saud family's ability to manage the inevitable generational shift from the sons of Saudi Arabia's founder to his grandsons, said Torbjorn Soltvedt, an analyst at global risk consultancy Verisk Maplecroft.

Another young prince also ascended to power on Wednesday. Prince Abdulaziz bin Saud, 33, was named the new interior minister tasked with counterterrorism efforts and domestic security. His father is the governor of Saudi Arabia's vast Eastern Province, home to much of the country's oil wealth and most of its minority Shiites. He previously served as an adviser to the interior and defense ministries.

Both young princes hail from the powerful Sudairi branch of the royal family.

The royal decree stated that "a majority" of senior royal family members — 31 out of 34 — from the so-called Allegiance Council support the recasting of the line of succession. The Council is comprised of senior princes who gather in secret and vote to pick the king and crown prince from among themselves.

Even when there is disagreement, the royal family has long followed a tradition of speaking with one voice, particularly on issues of succession, in order to appear united in front of Saudi Arabia's many tribes and communities.

After the decrees were announced, Saudi TV aired footage of the new crown prince warmly greeting the man he is replacing, Mohammed bin Nayef. MBS is shown kissing his older cousin's hand and kneeling before him; the outgoing crown prince is heard telling him: "I will rest now, and God help you."

Mohammed bin Nayef was once a towering figure credited with crushing al-Qaida's cells in Saudi Arabia. He worked closely with Washington after the Sept. 11 attacks, helping to share intelligence to thwart more attacks. Dubbed by Washington insiders as "the prince of counterterrorism," he developed a ground-breaking program that rehabilitates individuals convicted of terrorism-related crimes.

Though his image remained on billboards and atop buildings throughout Saudi Arabia, the 58-year-old prince appeared to be slipping in profile. Despite his longstanding Washington ties, it was Mohammed bin Salman, who embarked on major overseas visits, including a trip to the White House to meet Trump in March. That visit helped lay the foundation for the president's visit to Saudi Arabia in May, making the kingdom his first international stop. Saudi Arabia promoted the visit as proof of its weight in the region and wider Muslim world.

The warm ties forged between Riyadh and Washington under the Trump administration may have helped accelerate Mohammed bin Salman's ascension as crown prince.

Despite his ambitions, the prince has faced criticism for the Saudi-led war in Yemen, which has failed to dislodge Iranian-allied rebels known as Houthis from the Yemeni capital, Sanaa, and has had devastating effects on the impoverished country.

The newly-minted crown prince has also used fighting words to describe Iran, vowing to take "the battle" to the Shiite-ruled country. Iran and Saudi Arabia's rivalry has played out in proxy wars across the region and has deepened Sunni-Shiite enmity between hard-liners on both sides.

Batrawy reported from Dubai, United Arab Emirates. Associated Press writers Jon Gambrell and Fay Abuelgasim in Dubai contributed to this report.

Follow Aya Batrawy on Twitter at https://twitter.com/ayaelb