An NYPD sergeant urged a Midtown Starbucks to stop giving free food to the homeless after dozens of disturbance calls at the location.

But the coffeehouse, not far from the Port Authority Bus Terminal, ignored the warning and that same officer wound up being assaulted by a vagrant — who was angry over the quality of his free croissant, the officer charges in a lawsuit.

“I warned that someone would end up getting hurt — it was an unsafe environment. It turned out to be me,” Sgt. Timothy Wall told The Post.

And despite 80 disturbances involving vagrants at the store in 2017 alone, according to Wall’s suit, Starbucks says the officer has no one to blame but himself.

Starbucks lawyers say Wall brought on his injuries through his own “culpable conduct . . . and assumption of risk,” according to response papers filed in February.