Police say 41-year-old Michael Grimes was shot in the right leg while fleeing through the parking lot of the Golden Dove Diner just after 3 a.m. Thursday.
Grimes was hospitalized in stable condition at Staten Island University Hospital North, and charges are pending.
When the masked suspect burst into the 24-hour diner and announced a robbery, he did not realize that two officers assigned to the 122nd Precinct were sitting at a table.
They identified themselves and the suspect fled into the parking lot, where he exchanged gunfire with the officers.
Grimes jumped into a car he had stolen earlier and sped away. But he did not get very far, crashing at the end of Stone Lane, a dead end.
He was taken into custody, and police found a .380 caliber weapon under the car.
A Yankees baseball cap stuffed with cash was also recovered at the car, and police believe it was money stolen at an earlier robbery at a Perth Amboy diner.
Grimes has five prior robbery arrests, and 22 arrests total.