A serial transit bandit testified in a special hearing that he’s commandeered trains 5,000 times since his lifelong passion erupted at the tender age of 15 — when he was first arrested.

Darius McCollum, who has been busted over 30 times for illegally driving buses and trains in the city, took the witness stand in a special hearing to determine whether he is a danger to society and what kind of facility he will be committed to at his sentencing.

McCollum, who has Asperger’s syndrome, took a plea deal in January to his most recent bust, for stealing a Greyhound bus, on the condition that he would indefinitely be committed to a psychiatric facility.

Brooklyn prosecutor Janet Gleeson asked, “How many times have you taken [MTA] trains in your life without permission or authority?”

McCollum responded, “Probably a couple of thousand times,” noting he often wore MTA uniforms that he’d gotten from retired transit worker pals.

McCollum said if you factored in his hundreds of joyrides on LIRR, Amtrak and Metro North trains he had manned the controls some 5,000 times —despite no formal training.

He said his unofficial education in train operation started when he was just 12 and older MTA workers gave him pointers.

The transportation fanatic admitted that he knew he was risking the lives of Greyhound passengers when he drove them during a 2015 snow storm but said he did it anyway because, “They were shorthanded on staff.”

Gleeson pressed, “The only reason you drove those buses is because Greyhound was short that day?”

McCollum answered, “That would be affirmative. Yes.”

The 52-year-old also admitted to having forged ID’s for many of the transportation companies and agencies and said he bought fake CIA and Homeland Security badges that he would flash when people got suspicious.

“On the most recent time you drove a Greyhound bus in the snow did you ever consider the fact you should not be driving a huge bus with passengers in that weather?” Gleeson asked.

He answered, “I had to convince myself that I could do it. So I’m going to say that I had to get it done.”

Gleeson pressed, “What were you thinking when you were driving passengers in inclement weather?”

“I was concerned for the passengers to get them to the destination they had to go to,” McCollum plainly stated.

McCollum testified that he felt “important” when he was operating the trains and buses and said despite the risk of arrest he continued because, “It was my hobby and my passion.”

McCollum’s lawyer, Sally Butler, who began her cross-examination of him Wednesday afternoon said, “I am trying to get the judge to see the people who have Asperger’s don’t belong in a locked up facility.”

The hearing will continue on June 8.