A drunk BMW driver barreled into a Bronx railyard — then collided with train tracks and the high-voltage third rail, police said Thursday.

Queens man Stanley Hayden, 42, claimed he was just following his GPS when he drove into the MTA’s 239th Street Yard and crashed around 2:30 a.m Tuesday morning — although a breathalyzer allegedly found he driving over the legal booze limit, according to the NYPD.

Fortunately, the rail — which carries 625 volts of electricity, according to The City — was quickly powered down.

Hayden was taken into custody and charged with reckless endangerment in the second degree and driving under the influence, cops said.

The MTA claimed Hayden was only able to get through the yard’s gate because it was opened for another vehicle.

“The gate was open because we were letting a car out of the yard. There’s full-time security there,” the official said.

Subway service was not impacted by the collision, the MTA said.