Mohammed Shahabuddin, a former judge and a ruling party official, was sworn in as the president of Bangladesh on Monday, just months before a general election.

Shahabuddin, 73, was an anti-corruption commissioner and fought in the country's 1971 war of independence against Pakistan, the presidential palace said.

"He was sworn in as the 22nd president of the People's Republic of Bangladesh today," Shampad Barua, secretary of the president, told AFP.

He was elected by lawmakers in February after the ruling Awami League party nominated him instead of the speaker of parliament, who had been seen as the favourite.

Shahabuddin replaces Abdul Hamid, a former speaker and Awami League stalwart, whose second term expired on Monday.

The election comes as the country faces mounting protests over the next general election, scheduled to be held in January 2024.

The opposition has staged a series of giant protests in recent months, demanding that Prime Minister Sheikh Hasina step down and let a caretaker government hold a free and fair election.

The opposition accuses Hasina, who has been in power since 2009, of rigging the previous two votes, and Western countries and rights groups have also raised concerns. Hasina has rejected the demand.

If Hasina was forced to resign or the protests descend into chaos, the otherwise largely ceremonial presidential office could end up playing a bigger role. Although he enjoys few powers in his new position, Shahabuddin now oversees the military.

Chinese President Xi Jinping on Monday sent a message of congratulations to Shahabuddin, China's official news agency Xinhua reported.

China and Western countries are vying for influence in the South Asian country of 170 million people, with Beijing investing billions of dollars on infrastructure projects there under its Belt and Road initiative.

Russia is also building a $12.65-billion nuclear power plant outside Dhaka to improve the country's shaky electricity network.

Bangladesh has agreed to pay Russia about $300 million in yuan to settle payment for building the facility, Bloomberg News reported last week.