Thailand’s parliament gathered on Wednesday to vote for prime minister for the second time in less than a week — a test for democracy in a nation where a powerful military and its royalist allies have often pushed back against democratic change.

T​he Move Forward Party, ​led by ​Pita Limjaroenrat, 42, is pushing for change in Thailand, and won the most votes in the May general election​. But Mr. Pita cannot form a government unless he is elected prime minister by the Thai Parliament. ​

He lost a previous vote last week. If the Parliament again fails ​to elect a leader by the end of ​Wednesday, a third vote could be held as soon as Thursday.

Mr. Pita’s supporters may hit the streets en masse if he doesn’t win. A protest was planned for Wednesday evening, and some demonstrators wearing his party’s signature orange had already gathered outside the Parliament building by the afternoon.

Here’s what to know.

Mr. Pita’s party has proposed ambitious policies for challenging Thailand’s powerful institutions like the military and the monarchy. The party won 151 seats in Parliament, the most of any party, and 10 more than Pheu Thai, the populist party founded by Thaksin Shinawatra, one of Thailand’s most famous politicians.

Mr. Pita’s party has formed an eight-party coalition, which nominated him for prime minister last week. He came up short in the first vote because the Senate is controlled by military-appointed lawmakers who opposed his candidacy and the Move Forward platform.

In other countries, yes. In Thailand in 2023, no.

Becoming prime minister requires a simple majority of the 500-seat House of Representatives and the 250-seat Senate.

But the rules governing Senate appointments were drafted by the military junta that seized power from a democratically elected government in a 2014 coup. They effectively give senators veto power over prime ministerial candidates.

Last week, Mr. Pita won only 13 votes from the 249 senators who voted for prime minister. Analysts say he probably won’t fare any better on Wednesday.

Mr. Pita faces several challenges beyond getting the votes he needs.

On Wednesday morning, lawmakers gathered to discuss whether parliamentary rules allow a prime ministerial candidate to stand for a second vote after losing the first one. Some have argued that the rules prohibit resubmitting a failed motion; others say this is a special situation that requires an exemption.

Separately on Wednesday morning, the Constitutional Court said it was suspending Mr. Pita from Parliament until a ruling is made in a case involving his shares of a media company. Investigators are trying to determine whether Mr. Pita properly disclosed the shares before running for office, as required by Thai law.

The court’s ruling forced Mr. Pita to leave the chamber on Wednesday, but it would not necessarily prevent his coalition from nominating him as prime minister for a second time.

Mr. Pita’s supporters have said the investigation is the government’s attempt to unfairly derail his candidacy.

Mr. Pita has said that if it becomes clear that he cannot win, his party would allow its coalition partner, Pheu Thai, to nominate its own candidate.

Pheu Thai probably will nominate its own candidate, but is also likely to form a brand-new coalition, one that is more palatable to conservative lawmakers who cannot stomach Mr. Pita and Move Forward.

Pheu Thai’s candidate would likely be Srettha Thavisin, 60, a property mogul with little political experience.

Still, as prime minister he would immediately present a sharp contrast to the current one, former Gen. Prayuth Chan-ocha, who led the 2014 military coup.

A more remote, but not impossible, scenario is that Pheu Thai allows a party from the conservative establishment to nominate a candidate as a condition for joining a new coalition. That candidate could be Gen. Prawit Wongsuwan, 77, deputy prime minister in the current government.

Many would see a victory for Mr. Srettha as a triumph for the democratic process in Thailand, a country with a long history of mass protests and military coups. Some foreign investors would also view it as a potential boost for a sluggish, coronavirus-battered economy.

But many of Move Forward’s progressive supporters would be angry if their party was blocked from forming a government after winning the most votes in the May election. On Wednesday afternoon, hundreds of protesters stood outside the gates of the National Assembly in Bangkok. On the other side was a group of police officers, some in riot gear.

Another demonstration was planned for 5 p.m. at the city’s Democracy Monument.

The size of the protests over the next days or weeks will likely depend on who becomes prime minister. If it’s Mr. Srettha, demonstrations could be sporadic and modest. If it’s General Prawit or another military figure, they could be sustained and intense.

Most analysts agree that Mr. Pita’s chances remain thin.

Muktita Suhartono contributed reporting.