LOS ANGELES — Beyoncé made Grammy history on Sunday night, setting a record at the awards’ 65th annual ceremony for the most career wins by any artist, after picking up a string of trophies for “Renaissance,” her hit album that mined decades of dance music.

But she was once again shut out of the major categories, winning all four of her prizes for the night in down-ballot genre categories. Harry Styles took album of the year for “Harry’s House,” Lizzo won record of the year for her retro dance anthem “About Damn Time,” and song of the year went to Bonnie Raitt for “Just Like That.” It was Beyoncé’s fourth career loss for album of the year.

Styles seemed at a loss for words as he accepted his Grammy, opening his remarks with a stunned profanity.

Still, Beyoncé’s accomplishment resonated throughout the evening. Accepting her 32nd career award, Beyoncé thanked God and her family, and honored her “Uncle Jonny,” a gay relative whom she has described in the past as her “godmother” and as the person who exposed her to L.G.B.T.Q. culture.

“I’d like thank the queer community for your love, and for inventing the genre,” she said to roars of applause from the crowd at the Crypto.com Arena as she won best dance/electronic music album for “Renaissance,” which was widely seen as a love letter to gay culture. (Even so, Beyoncé faced a backlash recently when she performed a private concert in Dubai, in United Arab Emirates, where homosexuality is illegal.)

With her latest wins, Beyoncé surpassed Georg Solti, the Hungarian-born classical conductor who died in 1997 and had long held the title of the most career wins by any artist.

Even Beyoncé’s competitors cheered her on. Accepting record of the year, Lizzo told a story of being inspired by seeing Beyoncé in concert (while skipping school).

“You clearly are the artist of our lives!” she shouted. (In 2017, when Adele beat Beyoncé for album of the year, she said almost the same thing.)

Beyoncé also won best dance/electronic recording (“Break My Soul”), traditional R&B performance (“Plastic Off the Sofa”) and best R&B song (“Cuff It”). She had been the most nominated artist of the evening, with nine nods.

Gender freedom was a theme running through the night. Not long before Beyoncé’s win, Sam Smith, a nonbinary singer, and Kim Petras, a trans woman, won the award for pop/duo group performance for “Unholy,” and Petras drew cheers when she said she was “the first transgender woman to win this award.”

“I hope that there’s a future where gender and identity and all these labels don’t matter that much,” Petras told reporters backstage. “Where people can just be themselves, and not get judged so hard and not be labeled so hard.”

After two years of shows that were disrupted and delayed by the Covid-19 pandemic, the annual Grammy ceremony returned in full swing to its home court in Los Angeles (Crypto.com is the renamed Staples Center), bringing the music world together for glitz, competition and, behind the scenes, plenty of business schmoozing.

“We made it!” exclaimed its host, Trevor Noah. “We’re back!”

The power of stardom was another of the night’s major underlying themes. The show opened with a blast of brass and the hip-swaying rhythms of Bad Bunny, the Puerto Rican superstar who represents the music industry’s hopes — he is a young celebrity with global appeal and massive numbers, both on streaming services and on the road.

Walking through the aisles of the arena flanked by dancers in festive dress, he played two songs from his blockbuster album “Un Verano Sin Ti,” bringing both social commentary and party vibes, and getting stars like Taylor Swift dancing amid the bistro-style seating in front of the stage.

Accepting the award for best música urbana album for “Un Verano,” Bad Bunny gave his speech in Spanish and English.

“I just made this album with love and passion,” he said. “When you do things with love and passion, everything is easier.”

Old-fashioned song craft remains a key touchstone for Grammy voters. Raitt, 73, was the surprise winner of song of the year — beating Adele, Beyoncé, Swift, Lizzo and Styles, whose songs were huge hits — for “Just Like That,” a tender meditation about an organ donation that had only modest commercial success. She accepted it as a recognition of the job of songwriting itself, and thanked other writers for providing her with material throughout her career.

“I would not be up here tonight,” Raitt said, “if it wasn’t for the great soul-digging, hard-working people that put these songs and ideas to music.”

Samara Joy, a singer who brought fresh interpretations to jazz classics, and began her career posting them online, won best new artist.

In classic Grammy fashion, the ceremony also included some loving nods to the past.

Stevie Wonder led a Motown revue that included Smokey Robinson and the country songwriter Chris Stapleton. One of the highlights of the night was a 12-minute celebration of the 50th anniversary of hip-hop — the genre’s origin is tied to a birthday party in the Bronx in 1973 — that featured LL Cool J, Busta Rhymes, Salt-N-Pepa, Method Man, Chuck D and Flavor Flav of Public Enemy, Missy Elliott, Future, Grandmaster Flash and many others.

A somber, multipart “In Memoriam” segment included the country singer Kacey Musgraves singing Loretta Lynn’s “Coal Miner’s Daughter” barefoot in a blood-red dress; a tribute to Takeoff of the Atlanta rap trio Migos led by his bandmate Quavo; and Raitt, Sheryl Crow and Mick Fleetwood singing “Songbird,” one of the signature compositions by Fleetwood Mac’s Christine McVie, with Fleetwood tapping a drum like it was a gently beating heart.

Styles performed his bubbly, pensive hit “As It Was” in a silvery sequined suit with tassels that shook as he danced. “Harry’s House” also won Styles the award for pop vocal album.

Kendrick Lamar won three rap prizes: best performance and best song, for “The Heart Part 5,” and best album, for “Mr. Morale & the Big Steppers.” Accepting the album award, he thanked his family “for giving me the courage and giving me the vulnerability to share my truth and share these stories.”

Brandi Carlile, a Grammy darling in recent years, won best rock performance and best rock song for “Broken Horses,” as well as best Americana album for “In These Silent Days.”

The 89-year-old Willie Nelson, who was not present, won for best country album for “A Beautiful Time,” and best country solo performance for the song “Live Forever.”

Swift ended the night with one victory, best music video for “All Too Well: The Short Film,” but lost her three other nods — including her sixth career loss in song of the year for “All Too Well (10 Minute Version),” an extended remake of a song she first released in 2012.

The first lady, Jill Biden, announced the winner of a new award, best song for social change, which went to the 25-year-old Iranian songwriter Shervin Hajipour, whose song “Baraye” became an anthem for the women’s rights protests there last year. The prize was chosen by what the academy described as a “blue-ribbon committee.”

For an industry that has lately gotten worried about the difficulty minting stars amid the fire hose of content in the age of streaming and social media, this year’s list of nominations was about as good as it gets. It guaranteed plenty of star power and some drama over winners and losers. On Grammy night, drama is a good thing.

As much as the Recording Academy, the nonprofit institution behind the Grammys, promotes its mission of celebrating artistic excellence and being a supportive home for creators year-round, the Grammys is also a television show that needs to attract a large audience.

As they have for all major awards shows, ratings for the Grammys have been slipping for years. But the past two years have been brutal. In 2021, when the Grammys put on an outdoor show with no audience, its viewership fell to 8.8 million, the lowest ever; last year, when the show was delayed by the spread of the Omicron variant and held for the first time in Las Vegas, the number was only marginally better, at 8.9 million.

This year’s awards recognized music released between Oct. 1, 2021, and Sept. 30, 2022, and were selected by the 11,000-member voting body of the Recording Academy, which includes artists, songwriters, producers and other music professionals.

Of the 91 awards this year, all but a dozen were given out in a nontelevised ceremony on Sunday afternoon.

The actress Viola Davis won best audiobook, narration and storytelling recording for her memoir “Finding Me,” making her the newest EGOT — the coveted acronym for the winner of an Emmy, a Grammy, an Oscar and a Tony.

Among the new categories this year was songwriter of the year (non-classical), intended to recognize the writers who work behind the scenes. It was won by Tobias Jesso Jr., who has written songs for Adele, Styles and others. Stephanie Economou was the first winner for best score soundtrack for video games and other interactive media for her work on the game Assassin’s Creed Valhalla: Dawn of Ragnarok.

Below the superstar level, the Grammys have the power to transform artists’ careers. The Tennessee State University Marching Band was the first college marching band ever nominated for best roots gospel album, and it won with “The Urban Hymnal.”

Accepting that award, Sir the Baptist, one of the album’s producers, addressed the straitened finances of historically Black colleges and universities. “HBCUs are so grossly underfunded to where I had to put my last dime in order to get us across the line,” he said. “We’re here with our pockets empty but our hands aren’t.”