How to Start the New Year? Keep the Sea Goddess Happy.

Each New Year’s Eve, more than two million revelers — twice as many as typically fill Times Square — dress in white and pack Copacabana Beach in Rio de Janeiro to watch a 15-minute midnight fireworks extravaganza.

The one-night hedonistic release is one of the world’s largest New Year’s celebrations and leaves Copacabana’s famed 2.4 miles of sand strewed with trash.

But it began as something far more spiritual.

In the 1950s, followers of an Afro-Brazilian religion, Umbanda, began congregating on Copacabana on New Year’s Eve to make offerings to their goddess of the sea, Iemanjá, and ask for good fortune in the year ahead.

It quickly became one of the holiest moments of the year for followers of a cluster of Afro-Brazilian religions that have roots in slavery, worship an array of deities and have long faced prejudice in Brazil.

Then, in 1987, a hotel along the Copacabana strip started a Dec. 31 fireworks show. It was a huge hit that began attracting large numbers.

“Obviously, this was great for the hotel industry, for tourism,” said Ivanir Dos Santos, a professor of comparative history at the Federal University of Rio de Janeiro.

A new New Year’s tradition was born, and the revelers adopted some old Umbanda traditions, including throwing flowers into the sea, jumping seven waves and, especially, wearing white, a symbol of peace in the religion.

But the huge party, Mr. Dos Santos said, “also then pushed the worshipers off the beach.”

Not entirely.

Mr. Dos Santos was standing on Copacabana Beach, dressed in white, with the chants of Umbanda worshipers behind him. Yet this was Dec. 29, the date when devotees of the Afro-Brazilian religions now descend on Copacabana Beach to make their annual offerings to Iemanjá (pronounced ee-mahn-JA).

Alongside beachgoers in bikinis and vendors selling beer and barbecued cheese, hundreds of worshipers were trying to make contact with one of their most important gods. Devotees believe that Iemenjá, who is often depicted with flowing hair and a billowing blue-and-white dress, is the queen of the sea and a goddess of motherhood and fertility.

With temperatures exceeding 90 degrees, many gathered under a tent for traditional dances and songs around an altar of small wooden ships, loaded with flowers and fruit, that would soon be sent into the sea. Outside, they dug shallow altars in the sand, leaving candles, flowers, fruit and liquor.

“This is a tradition passed from generation to generation. From grandmother to mother to son,” said Bruna Ribeiro de Souza, 39, a schoolteacher, sitting in the sand with her mother and her toddler son. They had lit three candles and poured a glass of sparkling wine for Iemenjá. Nearby was their foot-long wooden boat, ready for its voyage.

Ms. Souza’s mother, Marilda, 69, said her own mother brought her to Copacabana to make offerings to Iemanjá in the 1950s. It was a way, she said, to reconnect with her family’s African roots.

Afro-Brazilian religions were largely created by slaves and their descendants. From about 1540 to 1850, Brazil imported more slaves than any other nation, or nearly half of the estimated 10.7 million slaves brought to the Americas, according to historians.

One of the most popular religions, Candomblé, is a direct extension of Yoruba beliefs from Africa, which also inspired Santería in Cuba. Residents of Rio created Umbanda in the 20th century, mixing the Yoruba worship of various deities with Catholicism and aspects of occultism.

Roughly 2 percent of Brazilians, or more than four million people, identify as followers of Afro-Brazilian religions, according to a survey conducted in 2019. (About half identified as Catholic and 31 percent Evangelical.) That was an increase from the 0.3 percent who said they followed Afro-Brazilian religions in Brazil’s 2010 census, the last official figures.

The religions have given many Black Brazilians a cultural identity and connections with their ancestors. But followers have also faced persecution. Extremists in the Evangelical church have called the religions evil, attacked their followers and destroyed their places of worship.

Still, as the sun set over Copacabana Beach on Friday, groups of beachgoers cheered on the worshipers as they marched into the surf with bouquets of white flowers, bottles of sparking wine and their wooden boats. (Environmental concerns led devotees to abandon Styrofoam boats, and they no longer load on things like bottles of perfume.)

Alexander Pereira Vitoriano, a cook and Umbanda worshiper, carried one of the largest boats and waded into the waves first. As he let the boat go, a wave capsized it, a sign to the followers that Iemenjá had taken the offering.

“She comes to take everything bad to the depths of the sacred sea, all the evil, the sickness, the envy,” he said on the shore, panting and soaked. “It’s a clean start to the new year.”

Nearby, Amanda Santos emptied a bottle of sparkling wine into the waves and wept. “It’s just gratitude,” she said. “Last year I was here and asked for a home, and this year I got my first house.”

After a few minutes, the surf became a line of flowers that had been thrown into the sea and were then spit back out. As the skies darkened and the crowd cleared, Adriana Carvalho, 53, stood with a white dove in her hands. She had bought the bird the day before to release it as an offering. She was asking Iemanjá for peace, health and clear paths for her family.

She let go of the dove, and it flittered into the sky. Then it quickly came down again, landing on the back of a woman bent over an altar in the sand. The woman, Sara Henriques, 19, was making her first offering.

The dove landed “at the moment we were asking for a good 2024, with health, prosperity and peace,” she said. “So, to me, it was a confirmation that my wish had been fulfilled.”