An emotionally disturbed homeless man shouting an anti-gay slur Thursday morning came within 15 feet of New York City's first lady before cops carted him away, the mayor's spokeswoman said.

Mayor Bill de Blasio's wife, Chirlane McCray, had been outside a subway stop in Brooklyn to pressure Albany to strengthen rent regulation when the man began his tirade.

The 48-year-old also spat at City Councilman Jumaane Williams, the NYPD said. Police found the man with a razor, the mayor's spokeswoman said. He was hospitalized but not arrested, she said.

He was sent to Kings County Hospital Center by an ambulance "for evaluation," the NYPD said.

The incident occurred shortly after 9 a.m. near the Flatbush Avenue-Brooklyn College, as McCray and other activists were handing out fliers advocating renewed regulation of the city's housing stock.

"The first lady was not in danger," de Blasio spokeswoman Karen Hinton said.

With Maria Alvarez