Karen Pendergrass kept seeing the lanky boy walk by the lunchroom where she taught dance twice a week to eighth grade students in North Philadelphia. He would peer inside, then run away as soon as Ms. Pendergrass made eye contact.

“You come peeking in my door one more time and you’re coming in my class,” Ms. Pendergrass told him. “From there, he never left.”

For the next 15 years, O’Shae Sibley danced, working on the side as a delivery man, waiter and cleaner between auditions and performances in Philadelphia and New York, where he moved to further his career. At 28, he was preparing to audition for “The Lion King,” one of his favorite Broadway musicals.

But on Saturday, Mr. Sibley and his friends made a quick stop at a Brooklyn gas station as they came back from a beach day. They were blasting Beyoncé and dancing around the car when a group of about three young men told them to stop and hurled gay slurs at them.

Summy Ullah, a 32-year-old gas station attendant who witnessed the encounter, said one of the young men said, “I’m Muslim. I don’t want this here.”

Mr. Sibley and his friends argued with them, and one young man began recording Mr. Sibley and his friends on his phone while cursing at them. Mr. Sibley followed the group and Mr. Ullah, who rushed over to prevent a fight, saw the young man who was recording pull out a knife.

Mr. Ullah said he did not realize Mr. Sibley had been stabbed until he saw the blood.

“I can’t forget what I’ve seen,” said Mr. Ullah. “It’s not the gay guys’ fault, because they were minding their own business. They didn’t do anything.”

The killing has shocked New Yorkers and galvanized the gay community with grief. Some are planning vigils and others have called on the public to gather at the Mobil gas station on Coney Island Avenue and “vogue as an act of resistance,” a reference to the stylized dancing that Mr. Sibley and his friends performed, one that mimics models’ poses and blurs the lines of gender.

On Thursday evening, at the Stonewall Inn, the Greenwich Village bar known as the cradle of the gay rights movement, about 80 mourners gathered. In a gospel cadence, they sang “O’Shae Sibley was freed today” as an ensemble of wind instruments played.

“He was just a beautiful spirit, a wonderful person, just exercising his freedom to be alive,” said Sunder Ganglani, 42, who rode his bike to the demonstration with a picture of Mr. Sibley attached to his rear wheel.

On Beyoncé’s website, “Rest in Power, O’Shae Sibley” was prominently displayed against a black backdrop. Mayor Eric Adams called the attack an act of homophobia that violated the city’s ethos of “knowing and loving people of all backgrounds.”

“We’ll bring justice for O’Shae’s family and loved ones,” he said in a social media post.

The police said they are searching for a man in his late teens in connection with the killing. The department’s hate crimes unit is assisting in the investigation.

Brian Downey, a New York Police Department detective and president of the Gay Officers Action League, said the attack underscores the violence gay people face even in a city that is supposed to be a “refuge, a place of safety.”

For Mr. Sibley, New York felt like a better haven than North Philadelphia, where he had to navigate the streets carefully, his friends said.

“For many Black gay men, there is code switching, where we have to walk more masculine presenting,” said Kemar Jewel, 31, a dancer and choreographer who met Mr. Sibley when they were teenagers in Philadelphia. “Maybe we’re wearing looser clothing or not looking people in the eye.”

Joan Myers Brown, founder of the Philadelphia Dance School, gave Mr. Sibley a full scholarship after Ms. Pendergrass recommended him.

She was impressed with his determination. In a family of 11 siblings, there was rarely extra money. Ms. Brown recalled driving him home late at night from the studio in West Philadelphia when he didn’t have car fare. Ms. Pendergrass often gave him food and clothing, Ms. Brown said.

“He had a tough fortitude,” Ms. Brown said “To handle New York, you have to be tough and he was handling it.”

In New York, Mr. Sibley moved freely. He vogued at Pier 47 on the Hudson River, a favorite hangout, and had a tight-knit group of friends who collaborated on videos, dance competitions and performances.

In June 2020, as the city was swept by demonstrations against police brutality, Mr. Sibley joined four other dancers who, dressed in black berets and black clothing, vogued in locations around the city for a video directed by Mr. Jewel. The video was meant to support the Black Lives Matter movement but also showcase the joy and resistance embodied in vogueing.

Mr. Jewel directed Mr. Sibley as he strutted, pirouetted and glided on tiptoe in front of masked police officers who watched him with curiosity.

“He was so intentional in his movements,” Mr. Jewel said.

Soft-spoken, quiet and friendly, Mr. Sibley would deflect tense moments with a joke or silly comment, his friends said. But he was unafraid of confronting homophobia and bristled when anyone warned him that being open about his sexuality could draw hostility.

Beckenbaur Hamilton, 51, a neighbor and friend of Mr. Sibley, who lived alone in a studio apartment in Brownsville, remembered a boisterous party Mr. Sibley threw on July 2.

He and his friends were dancing, playing loud music and drinking. Mr. Hamilton, who is gay, said he worried the “wrong person” would overhear them and react violently.

When he warned Mr. Sibley and his friends, they laughed off his concerns, Mr. Hamilton said.

“I’m just telling you for your own safety: You don’t know who is who,” Mr. Hamilton said he told them. “They said, ‘We are just living our truths.’”

Iquail Shaheed, 39, a dancer and choreographer, met Mr. Sibley when the dancer was about 16 and they were both at the Philadelphia Dance School. By that point, Mr. Sibley had joined the school’s second company and Dr. Shaheed, an alumnus assigned to mentor him, was urging the younger dancer to draw from his experiences as a boy for a piece set to the song “Someday We’ll All Be Free,” by Donny Hathaway.

It conveyed the feelings of a “young Black male coming of age in a world that was devastatingly hard for him,” Dr. Shaheed said. To help Mr. Sibley connect with the work, Dr. Shaheed asked Mr. Sibley to think about what it felt like to hide his sexuality and to protect himself from those who would show hatred toward him.

“I was really pushing him,” Dr. Shaheed said. Mr. Sibley struggled with the direction.

“O’Shae got really mad at me,” he said. “It would really get to him.”

The Monday before he died, Mr. Sibley met with Dr. Shaheed and said he wanted to take classes with him at his studio in Manhattan. He wanted intensive preparation for his “Lion King” audition.

“I wasn’t fully ready for the way you were pushing me when I was younger,” Mr. Sibley said, according to his friend. “I’m ready for it now. I know you’re not going to be easy on me.”

Mr. Sibley told him he had saved enough money to pay for the classes. Dr. Shaheed, who that week left for a performance in Belgium, had no intention of letting him pay. He planned to surprise Mr. Sibley with the news when he got back to New York.

Mr. Ullah said that just before the fight began on Saturday, he had been watching Mr. Sibley and his friends and was enjoying their exuberant display. Mr. Ullah said he tried to chase the young man who stabbed Mr. Sibley, but he jumped into a Toyota Highlander that sped off.

“This was the first time I saw a hate crime in this neighborhood where I work,” Mr. Ullah said.

“I’m Muslim myself,” said Mr. Ullah, who immigrated from Pakistan. “When I saw them dancing, I was laughing too but I wasn’t making fun of them. Everyone has their own perspective, gay, transgender. We have gay people in our countries as well. You don’t make fun of them. They don’t say anything to you. They aren’t making fun of you.”

Dr. Shaheed said after news of the stabbing broke, someone sent him a brief 2016 clip of Mr. Sibley dancing to the Donny Hathaway song.

He has tried to imagine how happy and liberated Mr. Sibley must have felt during the last minutes of his life, jumping and vogueing with his friends.

“He was free,” Dr. Shaheed said. “Dancing without a care in the world.”

Kitty Bennettcontributed research.