A thief snatched a cellphone from a 13-year-old subway rider and tried to flee on the tracks in Queens on Tuesday — but karma caught up to him when he ran into an oncoming train, police sources and witnesses said.

The 33-year-old crook grabbed the phone and bolted from an M train into a subway tunnel near the Northern Boulevard station in Woodside at around 8 a.m., the sources said.

But the brainless bandit made it only a short distance before spotting a Manhattan-bound F train — packed with rush-hour commuters — barreling toward him, according to police and MTA sources. The train sideswiped the man near the 65th Street subway station, leaving him with cuts and bruises, MTA sources said.

“He was running down there like a trapped rat with trains speeding around him,” said a transit superintendent.

The crook claimed he had been zapped by a third rail, and was bawling like a baby when the superintendent found him, he said.

“I came up on the guy and he was crying, saying he got shocked by the train, saying he got electrocuted. His lip was bleeding. When I saw him, he was on his knees with some blood on his lip, drooling, moaning,” he said.

Morning commuters had to wait more than an hour while firefighters and police tended to him, MTA sources said.

MTA workers were forced to cut the power on the tracks to save him, said conductor Richard Keyes, who was operating the train that struck him. Keyes also flagged down an E train so it wouldn’t hit him, he said.

“If I didn’t do everything the way I did, he definitely would have been dead,” said Keyes.

The crook, who was wearing a cast on his arm, also roughed up the 13-year-old straphanger before stealing the cellphone, an MTA source said

When another commuter tried to stop him, he struck him in the face with the cast, an MTA official said. “He had assaulted a customer. The cellphone was found on him at the hospital when he was searched,” the transit superintendent said.

The crook walked away without any serious injuries.

Initially, a Manhattan-bound F-train operator heard something hit the train, stopped and found the alleged thief, said MTA officials. The agency responded by diverting all trains onto the express tracks.

The thief also caused delays on the E, M and R lines.

The man was recovering at Elmhurst hospital on Tuesday.

Cops had made no arrests and declined to name the robber on Tuesday.

Additional reporting by Danielle Furfaro and Natalie O’Neill