Mayor Zohran Mamdani failed to secure the release of a New Yorker shot by federal agents on Thursday. Despite his efforts to call President Trump, the mayor faced protests from his own base. He said, "to ensure that we're using every opportunity we have to deliver for this city."

In several phone calls over the course of two hours on Thursday evening, Mayor Zohran Mamdani pleaded with President Trump and his homeland security secretary to release a New Yorker whom federal immigration agents had shot and then detained.

The mayor's effort failed.

Then, as he stood next to his police commissioner, Jessica S. Tisch, at a news conference Thursday night, calling for the abolition of the Immigration and Customs Enforcement agency, his words were nearly drowned out by protesters chanting, "Mamdani is complicit." Blocks away, his Police Department was clashing with another set of protesters at the hospital where the shooting victim was being treated.

Mr. Mamdani, a 34-year-old democratic socialist, has until now managed to maintain the steadfast support of his left-wing base while moderating some of his positions as he adjusts to a job often described as the country's second hardest. He has kept as police commissioner Ms. Tisch, a technocratic billionaire who has criticized liberal policies on criminal justice. He has also developed a surprisingly warm relationship with Mr. Trump.

In a brief interview on Friday, the mayor insisted that the purpose of his friendly meetings with the president was "to ensure that we're using every opportunity we have to deliver for this city."

But after the shooting, that relationship failed him, raising immediate questions about its value in New York, a city of immigrants where Mr. Trump is broadly unpopular and where Mr. Mamdani's left flank is increasingly restive both about Washington's deportation campaign and about policing at the local level.

"What have we seen from the Trump administration for New York?" asked Alyssa Aguilera, the co-executive director of VOCAL-NY, an advocacy group for low-income New Yorkers. "Not much."

The heckling on Thursday came just a day after pro-Palestinian demonstrators jeered Mr. Mamdani and called him a "traitor" during a peace vigil he was attending to mourn those killed in the Oct. 7 attacks on Israel and in the war in Gaza. Among their grievances was Mr. Mamdani's decision to meet with Mr. Trump despite having called him a fascist.

The president's continuing crackdown on immigrants in New York burst into public view around 4 p.m. on Thursday when a plainclothes immigration agent shot and wounded Oscar Belgal while trying to arrest him in his car, in front of his 5-year-old son. Federal officials later said Mr. Belgal, a Dominican immigrant, had a grand larceny conviction, had refused orders to exit his car and had "weaponized his vehicle." Police officers arrived shortly after the shooting and took Mr. Belgal to NewYork-Presbyterian Allen Hospital.

Protesters soon gathered at the scene of the shooting in the Marble Hill neighborhood and at the hospital. And as Mr. Mamdani tried to negotiate with the president, police officers established a perimeter around the hospital, where ICE agents ultimately took Mr. Belgal into custody.

As the night wore on, the protests devolved into clashes with officers. At one point amid the chaos, officers pushing back the crowd shoved Darializa Avila Chevalier, a Democratic nominee for Congress, to the ground.

Ms. Avila Chevalier said on Friday that the Strategic Response Group, a controversial police unit that the mayor has vowed to disband, was also on the scene.

The Police Department said the unit did not respond to the protests, and was merely on standby. But questions about its presence further fueled calls from Mr. Mamdani's ideological allies for him to honor his promise to dismantle it. In the interview, Mr. Mamdani said he was still committed to doing so, and that he would have an update on that "soon."

In an interview, Ms. Avila Chevalier took particular issue with what she cast as the police's failure to de-escalate the situation, and with Ms. Tisch's decision during the Thursday night news conference to mention Mr. Belgal's criminal record.

In response to that criticism, the Police Department said on Friday that it is standard practice to release factual updates about police incidents.

Ms. Avila Chevalier said the Police Department and Ms. Tisch had "violated the spirit, if not the letter, of our sanctuary city policies," referring to laws that limit cooperation between local law enforcement officials and immigration authorities.

A fellow democratic socialist, Ms. Avila Chevalier has close ties to the mayor. Nevertheless, on Friday, she called for his police commissioner to step down.

Mr. Mamdani responded that Ms. Tisch was going nowhere.

"Jessica Tisch is the police commissioner and there are no plans to change that," Mr. Mamdani said in an interview, adding that he and the commissioner would conduct a review of "all of the events of the last 24 hours."

But he also condemned the Police Department's treatment of Ms. Avila Chevalier.

"I do not think it is acceptable to throw anyone to the ground in our city," the mayor said. "I believe that to be true when it applies to the congresswoman-elect and, frankly, any New Yorker."

It has been a challenging week for Mr. Mamdani, with "a few events coming together at the same time creating a perfect storm for him," said Gustavo Gordillo, the co-chair of the New York City chapter of the Democratic Socialists of America, Mr. Mamdani's political home. Mr. Gordillo acknowledged frustration with Mr. Mamdani among members of his base.

"I think people don't just want symbolic gestures in response to things like the genocide and an ICE shooting," Mr. Gordillo said. "And we're going to partner with the mayor, I'm sure, to develop concrete policies. But I think it's an area where we need more development."

On immigration enforcement, Mr. Gordillo said: "We think the police commissioner needs to call off the police from aiding ICE in these situations. And if she cannot fulfill that, then she needs to resign or be fired."

The Police Department said on Friday that officers had done nothing to assist ICE's operations, and that they had only transported Mr. Belgal to the hospital and responded to the ensuing protests.

On Friday, Mr. Mamdani suggested that he empathized with his detractors.

"I think that people are restive and so am I," he said. "I am, frankly, furious. I'm in pain hearing from families whose loved ones were killed by Hamas on Oct. 7. I'm angry that the genocide in Gaza continues and has killed 74,000 Palestinians. I'm outraged that ICE agents dressed up in construction vests carrying long guns shot at a man and his 5-year-old child in our city streets, and I understand people feeling the same."

During Mr. Mamdani's Thursday evening talks with Mr. Trump and Markwayne Mullin, the homeland security secretary, the mayor offered to take over the investigation into the shooting but said the city would not detain Mr. Belgal because it had no legal basis to do so, according to a person briefed on the call.

"I made clear we would not take him into custody and that we would not do their job for them," Mr. Mamdani said.

The White House and Department of Homeland Security referred reporters to the department's prior statements on the matter.

That Mr. Mamdani and Mr. Trump's relationship should fail to yield results in this situation is not particularly surprising, said Stu Loeser, who served as press secretary for former Mayor Michael R. Bloomberg.

"Zohran Mamdani is the most telegenic political communicator in America, and President Trump loves to associate himself with that," Mr. Loeser said. "The president of the United States still has the biggest bully pulpit in America and the mayor of our biggest city is smart to try and appear behind it sometimes."

But, he continued, Mr. Trump's "aggressive anti-immigration strategy" is one of his "central campaign promises."

"This is a deliberate policy and political strategy by the president, and he's not likely to back off it for any reason," Mr. Loeser said.