Hundreds of millions of Hindus are convening this week in what is expected to be the world’s largest human gathering, where a staggering number of devotees, tourists, politicians and celebrities take sacred dips at the convergence of two holy rivers in India.

The religious festival, called the Maha Kumbh Mela, happens every 12 years on the banks of the Ganges and Yamuna rivers in the northern Indian city of Prayagraj. Officials this year expect up to 400 million people — more than the population of the United States — to visit the site in Uttar Pradesh State over the next six weeks.

A major display of Hinduism, the event has recently become an important political event with the rise of Hindu nationalism, backed by Prime Minister Narendra Modi’s right-wing political party. It is also a massive logistical undertaking for government officials working to prevent incidents like stampedes and the spread of diseases.

The Maha Kumbh Mela, or “great festival of the sacred pitcher,” is the world’s largest religious ceremony. Based on a Hindu legend in which demons and gods fight over a pitcher carrying the nectar of immortality, the centuries-old ceremony centers on a series of holy baths, which Hindus say purify their sins.

The holy baths are preceded by processions involving people singing and dancing in vibrant attire, in ornately decorated chariots and wielding ceremonial spears, tridents and swords. To participate, people travel from all over India and the world to the junction of the Ganges and Yamuna rivers, a sacred site that is also said to be the end point of a mythical third river, the Saraswati.

The timing of the festival, which this year ends on Feb. 26, is based on the astrological alignment of the sun, the moon and the planet Jupiter, which takes around 12 years to orbit the sun. Smaller versions of the festival happen in one of three other Indian cities — Haridwar, Nashik and Ujjain — roughly every three years.

The scale of the Maha Kumbh Mela is astonishing. The last one, in 2013, drew 120 million people in Prayagraj, according to a government estimate. An intermediate festival in 2019, though less significant religiously, attracted 240 million people.

This year, the city, home to about 6 million residents, is preparing to host 300 to 400 million people, government officials said. In preparation, the state has built a temporary campsite across a 10,000-acre area, with tens of thousands of tents and bathrooms, roads, parking lots, water and electricity infrastructure and thousands of security cameras and drones.

Many of those preparations — which will most likely make this the most expensive Maha Kumbh Mela to date, at about $800 million — are meant to prevent deadly stampedes and outbreaks of disease, which have happened in previous festivals. The event is also expected to generate billions of dollars in revenue for the state government, officials said.

To accommodate the bathers, the government has also installed a platform made of sandbags along a seven-mile stretch of the Ganges riverbank. On Monday and Tuesday, millions of pilgrims poured into the river on those steps in the chilly morning fog, praying for happiness, health and prosperity.

The Maha Kumbh Mela has always been an important symbol of Hinduism, though it was usually not politicized until the recent rise of the idea of India as a Hindu nation. This year’s festival is the first since Mr. Modi’s Hindu nationalist political party, the B.J.P., became the country’s ruling party 11 years ago.

“It would be interesting to see if Prime Minister Modi goes,” said Arati Jerath, a political analyst in New Delhi. “It’s supposed to be the biggest and most auspicious time to take a dip in the Ganges.”

Yogi Adityanath, Uttar Pradesh’s chief minister who is also a hard-line Hindu priest, changed the name of the festival’s host city in 2018 to Prayagraj from Allahabad. The move, part of a wave of changes brought on by the B.J.P., replaced the Muslim name given by the 16th-century Mughal emperor Akbar with one that references the Hindu pilgrimage site.

In 2019, when India held a general election, the Kumbh Mela presented a major political opportunity to Mr. Modi and his party to appeal to a receptive audience of millions. Mr. Modi won that election.

The next general election is farther away this time, scheduled for 2029. But Mr. Modi, who won by a smaller margin while his party suffered losses in last year’s vote, has put himself in promotional posters for the festival nationwide and called it an embodiment of “India’s timeless spiritual heritage” on social media, tying the spiritual event to the country’s national identity.

“The B.J.P. is hoping to use it to solidify its Hindu nationalist base,” Ms. Jerath said. But she added it was unclear if that would necessarily earn the party more votes. “Whether it works or not, I don’t know, but it certainly helps to take the B.J.P. one step closer to its goal of turning India into a Hindu majoritarian nation.”