The prime suspect in the fatal stabbing of Tessa Majors was finally taken into police custody for what sources said was a DNA test Thursday morning — but was back on the streets just hours later.

The unidentified 14-year-old — who spent more than two weeks on the lam — was exclusively photographed by The Post while leaving his defense lawyers’ offices in Harlem around 4:45 p.m.

Neither the boy nor two apparent family members — a woman and an older teen — would answer questions, although the woman angrily slapped a recording device out of a reporter’s hand while crossing 125th Street.

see also Suspect in Barnard student's killing spotted coming out of NYC law office The prime suspect in the fatal stabbing of Barnard College...

“Go ahead! You’d better go ahead! Move! F–-k!” she shouted.

A man in a suit who emerged from the building that houses the Neighborhood Defender Service of Harlem to escort the group to a waiting SUV also refused to answer questions.

Detectives apprehended the teen before 8 a.m. in the Bronx and took him to the 26th Precinct station house in Harlem, where they executed a search warrant and swabbed a DNA sample from the inside of his cheek, sources familiar with the ­investigation said.

Cops hope to match the teen’s DNA to blood found at the scene of the crime or to genetic material recovered from Majors’ teeth after she bit one of her assailants, a source familiar with the case said.

DNA tests usually take three to four weeks, but can be done in as few as three days if the lab is “up and running” at full speed, sources said.

The teen’s test will be expedited, sources said, but it’s unclear whether the Christmas and New Year’s holidays will prevent it from being finished as quickly as otherwise possible.

The teen allegedly has been identified as Majors’ killer by 13-year-old Zyairr Davis, who’s charged with second-degree murder as an accomplice in the high-profile slaying of the Barnard College freshman.

Davis’ account of the teen’s role in Majors’ slaying provides enough probable cause to arrest the teen, a law enforcement source said, but a single accomplice’s testimony isn’t sufficient to secure a conviction under state law.

As a result, he could only be held for five days before he would be able to win his release from custody.

Neither the NYPD nor the Manhattan DA would say who made the decision to release him.

NYPD Chief of Detectives Rodney Harrison said the teen was released without charges following what he described only as an “investigative process” for which his lawyers were present.

“This was a significant development in the investigative process,” Harrison said.

“Although he has since been released to the custody of his attorneys, the investigation remains very active.

“Our detectives are the best at what they do and are committed to finding justice for all parties involved,” Harrison added.

But the teen’s revolving-door treatment left some cops fuming.

“Of course I’m outraged, and I feel sorry for Tessa’s family because after losing such a beautiful person, they have to now watch New York City politics victimize her a second time,” one Manhattan cop said.

“This is what the de Blasios, Cuomos, AOCs, all these politicians want — nobody to go to jail,” he said referring to US Rep. Alexandria Ocasio-Cortez.

A high-ranking NYPD official advised people to “move out of the city.”

“We’re in bad shape. Lucky it ain’t my daughter,” the source said.

Majors, an 18-year-old from Charlottesville, Virginia, was repeatedly knifed when she resisted a robbery around 5:30 p.m. on Dec. 11 in Morningside Park, on the western edge of the campus that the all-women’s Barnard school shares with Columbia University.

Davis allegedly confessed that he saw “feathers come out of her jacket” during the vicious attack, a detective who took part in the boy’s questioning testified in Family Court following his Dec. 13 arrest.

Davis also allegedly admitted that he and two pals from nearby MS 180 went to the park to rob someone, Detective Vincent Signoretti testified.

Another 14-year-old was also taken into custody Dec. 13, but was released for lack of evidence when he demanded a lawyer and refused to answer questions, sources have said.

The teen who was nabbed on Thursday was the subject of a Dec. 16 manhunt in Harlem sparked by his mother’s claim that he jumped out of a car while heading to the 26th Precinct with an unidentified adult to discuss the case, according to sources.

Subsequent investigation led authorities to suspect the teen was hiding out with relatives “down South,” and the New York-New Jersey Regional Fugitive Task Force was enlisted to try to track him down, sources said earlier this week.

Investigators now suspect the mother’s account of him bolting from the car was a ruse to give her son time to go into hiding, sources said Thursday.

Additional reporting by Rebecca Rosenberg and Bruce Golding