According to Wikipedia, the last farm plot in Manhattan sold in 1954.
https://en.wikipedia.org/wiki/Inwood,_Manhattan
I doubt it was a real commercial farm, however. Probably just a plot of land with some minor agricultural uses. There's technically a working farm in Queens, right now, but it's city-owned plot for teaching kids about agriculture.
Inwood was never an island, but Marble Hill, now attached to the Bronx, was formerly part of Manhattan Island. The Harlem River was re-routed at some point.
Upper Manhattan was the boonies until the subway reached the area, then there were huge waves of midrise apartment construction, mostly filled by upwardly mobile Irish and Jews moving to nicer accommodations. There are still Irish and Jewish enclaves way uptown, west of Broadway, with elderly that are probably one generation removed from original apartment dwellers.