Subway riders sat on dark trains over the Williamsburg Bridge for nearly two hours Wednesday night as authorities tried to capture a loose dog on the tracks.

The MTA said Queens-bound M trains were turning back at Marcy Avenue and not going over the Williamsburg Bridge because crews were trying to get a dog off the tracks on the bridge, according to officials. The dog was spotted just south of Marcy Avenue.

Power was cut to the tracks and trains as emergency responders got onto the tracks to try to retrieve the dog.

The MTA said the dog had been rescued and service resumed by late Wednesday night -- but people on stuck trains said they were still on the bridge, some for two hours.

"J train to BK, been about an hour on the bridge," one man tweeted to News 4 at around 11 p.m. "Police walked through the train with Chinese takeout, crawled underneath, all around. The dog evaded many capture attempts. Power was cut, restored, cut again, restored again. Many false starts, still here."

It's not the first time a dog on the tracks has halted subway service in recent months. Last February, a runaway dog named Dakota escaped from a dog park and leaped onto the tracks at Jay Street-Metrotech. And last March, a spaniel mix named Myko wound up on the tracks at Hoyt-Schermerhorn during a nor'easter. Both dogs were safely rescued.