New York is a city with some of the worst income inequality in the country. But when it comes to inequality of life spans, it’s one of the best.

Impoverished New Yorkers tend to live far longer than their counterparts in other American cities, according to detailed new research of Social Security and earnings records published Monday in The Journal of the American Medical Association. They still die sooner than their richer neighbors, but the city’s life-expectancy gap was smaller in 2014 than nearly everywhere else, and it has shrunk since 2001 even as gaps grew nationwide.

That trend may appear surprising. New York is one of the country’s most unequal and expensive cities, where the poor struggle to find affordable housing and the money and time to take care of themselves.