In a tragic case of mistaken identity, police shot and critically wounded an off-duty officer as he pointed a gun at a suspect outside a fast food restaurant early Saturday, authorities said.

Eric Hernandez, 25, was hit three times and was hospitalized in extremely critical condition, Mayor Michael Bloomberg said.

The officer who pulled the trigger, identified only as a 20-year veteran of the force, was being treated for trauma at another hospital.

Hernandez had been in line at a White Castle restaurant in the Bronx shortly before 5 a.m. when he was assaulted by a half-dozen men, Bloomberg said. It wasn't immediately clear what sparked the fight, but it was captured on the restaurant's security camera.

A White Castle employee called 911, and Hernandez — with his gun drawn — ran into the parking lot after his assailants, Bloomberg said.

He apparently subdued one of the suspects, and when a patrol car arrived, was pointing his gun at a man on the ground.

One of the two officers, apparently believing Hernandez was about to shoot,in the car opened fire, Police Commissioner Ray Kelly said.

Hernandez, who joined the force last year, never fired his weapon, authorities said. He was shot in each leg and the abdomen and lost a lot of blood, Bloomberg said.

Kelly said officials were questioning eight individuals about the shooting, including the six who fought with Hernandez inside the White Castle.

It was believed to be the NYPD's first friendly fire shooting since Desmond Robinson, who wasn't in uniform, was shot in the back by an off-duty officer in 1994. Robinson had his gun drawn on a subway platform, and the officer mistook him for a criminal.