OAKS, Pa. — Former President Donald Trump was about 30 minutes into a town hall event Monday night in suburban Philadelphia when a medical emergency in the crowd brought the questions and answers to a halt. Moments later, he tried to get back on track, when another medical incident seemed to derail things, this time for good.

And so Trump, a political candidate known for improvisational departures, made a detour. Rather than try to restart the political program, he seemed to decide in the moment that it would be more enjoyable for all concerned — and, it appeared, for himself — to just listen to music instead.

Trump had his staff fire up his campaign playlist, standing on the stage for about a half-hour and swaying to songs as his crowd slowly dwindled.

He bobbed his head through the Village People’s “Y.M.C.A.,” his usual closing song. He swayed soberly to Rufus Wainwright’s version of “Hallelujah,” watched a Sinead O’Connor video, rocked along to Elvis, watched the crowd during “Rich Men North of Richmond” and then, finally, left the stage to shake hands on his way out during one last song.

The impromptu DJ session was a strange conclusion to a political event that had started on familiar turf.

Aided by South Dakota Gov. Kristi Noem, Trump answered questions in front of hundreds of people at the Greater Philadelphia Expo Center in Oaks, Pennsylvania, about 18 miles northwest of Philadelphia.

The inquiries from friendly audience members allowed Trump to rattle off a series of talking points about the economy and immigration and attacks against Vice President Kamala Harris. But the event’s tone shifted about 30 minutes in, when two people in the crowd needed medical attention after apparently passing out.

As medical personnel responded to the first incident and the room grew tense, Trump asked his campaign staff to play a rendition of “Ave Maria.” Minutes later, after the person was removed on a stretcher, Noem tried to return to the Q&A session. But that effort stopped abruptly because a second person, a woman, also suddenly needed medical attention.

After the woman got up and walked to the periphery of the event, Trump called for some air conditioning in the venue. Noem, trying to get back on message, made a joke about inflation, saying, “They probably can’t afford it, sir.”

Then, Trump suggested a return to his comfort zone. He called up a chart on immigration that he has displayed at nearly every recent campaign rally and ordered up “Ave Maria” again. And after it played one more time, Trump decided to end the Q&A session after just five questions.

“Let’s not do any more questions. Let’s just listen to music,” he said. “Let’s make it into a music ... Who the hell wants to hear questions, right?”

Trump’s crowd cheered in approval, an indication of how his supporters flock to his rallies to be in his presence as much as to hear him make political points with which they are intimately familiar.

The playlist session was a glimpse of the private version of Trump seen more often at Mar-a-Lago, his residence and club in Palm Beach, Florida, than at political events. The former president has been known to take out an iPad that is connected to the speaker system there and play DJ for his guests.

As Trump stood through the first few songs, basking in the admiration of his supporters, the crowd packed into the expo center largely stayed put, recording him on their phones and at points singing along.

But Trump generally returns to his planned remarks after medical issues at other events. On Monday, he seemed more uncertain how to proceed. After offering what appeared to be a closing statement and having his campaign play a James Brown song, Trump suggested taking another question or two. As the crowd cheered in approval, he said, “let’s go,” but then said he’d play “Y.M.C.A.”

But after “Y.M.C.A.” ended, Trump seemed a little perplexed. “There’s nobody leaving,” he said. “What’s going on?” The audience cheered, and so the music kept going, as Noem stood awkwardly by.

Still, as one song became two, then three, many of those in the back of the house began to filter out. As the opening chords of the Guns N’ Roses power ballad “November Rain” played, one of Trump’s aides, Justin Caporale, came on the stage with a sheet of paper.

Trump briefly reviewed it. Then, seconds later, Trump waved, pumped his fist and finally left the stage.