Headlining Coachella on Saturday night in front of the weekend’s biggest crowd so far, the pop superstar gave as thrilling and complex a performance as any I’ve ever seen at the annual desert festival. It was wild but controlled, funny but scary, deeply tender yet filled with aggression.

Or at least that’s how it felt for about 45 minutes.

That’s when Lady Gaga, so close to greatness that even we in the audience could taste it, sadly stalled out, her momentum undone by poor song choices and a coarse promotional plug that made the whole show feel like a mere inducement to buy something.

But, oh, those first 45 minutes!

Taking the stage in a floor-length leather coat out of “Raiders of the Lost Ark,” Lady Gaga opened with a song whose title in German loosely translates as “Crap,” a relatively deep cut from her 2011 album “Born This Way.” It was a crazy selection, one nobody could have predicted, but the song’s pounding stadium-rave beat set the tone for the high-energy throwdown to come.

She remade “Just Dance” as a slamming hard-rock tune. She dropped a bit of Dr. Dre’s “Nuthin’ But a ‘G’ Thang” into “LoveGame.” She dedicated “John Wayne” to all the “dangerous men” who come to music festivals, then growled through the song in a manner that made it clear they were the ones with something to fear.

Before the title track from “Born This Way,” the empowerment anthem that’s made her a hero to many LGBTQ fans, Lady Gaga said she’ll never forget when she put the song out because it “caused so much trouble.”

“And I love causing trouble,” she said, adding an unprintable word for emphasis.

Throughout these songs — and several more that were just as intense, including “Venus” and “A-Yo” — Lady Gaga moved and sang with what looked and sounded like real abandon. For “Sexxx Dreams” she was surrounded by a crew of male dancers wearing small pieces of denim, and for once at a pop concert the choreographed display actually put across a realistic sensation of desire.

Yet Lady Gaga wasn’t lost in the moment. In the frequent close-ups that flashed on Coachella’s giant video screens, you could see how hard she was concentrating on the job at hand, which went deeper than simply entertaining a massive festival crowd. She had to make us look past the fact that she was filling in for a pregnant Beyoncé, who’d been booked for Coachella but pulled out in February on the advice of her doctor.

At her best, Lady Gaga succeeded in that mission — and not because we forgot about Beyoncé. Indeed, she reminded everyone on the polo field who was originally supposed to be there when she did the two singers’ duet, “Telephone.”

Instead, she was providing her own unique energy, an intensely focused beam of the cartoon-rebel charisma lacking from last year’s so-so “Joanne” album and her disappointing performance at the Super Bowl halftime show.

If the curtain had come down at that point, I’d be happily telling you that Lady! Gaga! Is! Back!

But that’s not what happened.

Oh, a curtain came down, all right — a digital approximation of one, anyway, that served as the video backdrop for a supper-clubby rendition of one of her least convincing songs, “Alejandro.” Then she did the even snoozier “Teeth,” of all things, a deeper cut than that German-titled song that didn’t have the advantage of a melody.

As she often does, Lady Gaga took to a keyboard for several numbers, which in theory was fine: Anyone would need a breather after what she’d just pulled off, and few have the natural pipes she does.

But doing “The Edge of Glory,” perhaps the most fist-pumpingly triumphant song in her catalog, as a dreary piano ballad? The idea was bananas, especially given that she then performed her country-ish “Million Reasons” — a tune that actually justifies a restrained presentation — in its corny EDM-remix form.

This was also the part of the show when Lady Gaga premiered “The Cure,” a new single she hadn’t spoken of until then. It’s an intriguing midtempo pop-soul jam — very Madonna circa “Human Nature.” (With its proudly synthetic textures, it also signals that the singer is moving on from the more rock-attuned “Joanne.”)

But “The Cure’s” placement on the set list only further diminished the excitement she’d been building.

Lady Gaga wisely upped the pace — and the snarling attitude — for her encore, zooming through “Poker Face” and “Bad Romance” in a way that somehow made those well-worn classics feel fresh.

Unfortunately, after “Bad Romance” she still had a minute or two before Coachella’s curfew, so she took the opportunity to speak to the crowd.

And what did she tell us at this fraught historical moment? That her new song was available to download on iTunes.

In addition to a thrilling headline performance on Saturday night (Apr. 15), Lady Gaga is preparing to shoot portions of her big screen A Star is Born reboot at Coachella this week along with co-star Bradley Cooper. The official Coachella app featured the invitation, which said that Gaga is slated to film scenes for the film at Empire Polo Club, the same location in Indio, California, where Coachella takes place.

Cooper is making his directorial debut in the latest remake of the film that famously chronicles the story of an up-and-coming starlet who struggles to break into the entertainment world with guidance from an industry veteran on the way down. The Oscar-winning actor will reportedly join Gaga onstage on Tuesday (Apr. 18) and Wednesday (Apr. 19) to film some scenes that take place during a country concert.

The solicitation for extras (which you can read here) invites Little Monsters to "be in the audience as Bradley Cooper and Lady Gaga films scenes on the actual Coachella stages. Help cheer and applaud their performances on camera... the scenes for these days will portray a Country Western music concert. All you Monsters that can attend should get decked out in your most comfortable denim & boots, throw on a Stetson (leave those pink Joanne hats at home) and come out to show your support!"

The app solicitation -- which noted that attendees' phones will be locked in a Yondr pouch to avoid leaked footage -- came on Sunday morning (Apr. 17), just hours after Gaga played to a massive crowd in a headlining slot originally held by Beyoncé, who had to beg off due to her pregnancy. In addition to playing a string of hits, Gaga also debuted the new track "The Cure" during the 90-minute set.

Tickets for the special event are $10 (attendees must be 18+), with all proceeds going to Gaga's non-profit Born This Way Foundation.