The Manhattan District Attorney’s Office dropped the ball and let two cases against suspected Chinatown killer Randy Santos languish until a judge was forced to dismiss them, The Post has learned.

On April 25, 2018, Santos was in court on an assault case for slugging a man in the face when he began to “whistle loudly while court was in session,” according to a pair of sealed criminal complaints obtained by The Post.

A court officer escorted him to the hallway, but Santos, 24, allegedly went berserk and tried to re-enter the courtroom, which landed him in cuffs, the papers say.

“I need to be somewhere by 4 o’clock,” he allegedly ranted as he shoved the court officer with his shoulder and strolled back into the courtroom, according to the complaint.

The officer dragged him out and struggled to arrest him, but Santos flailed his arms and twisted his body, the complaint states.

While being processed on charges of resisting arrest and obstruction, he was cuffed to a bench and wildly kicked at passing court officers, sources told The Post. He was later released on $500 cash bail, court records show.

His new case and his prior assault case dragged on for months. Then, on Nov. 28, 2018, Santos got a lucky break.

Prosecutors said they still weren’t ready for trial, and Judge Joanne Watters was forced to drop the charges against him in both cases on speedy trial grounds, according to sources and court records.

If a case doesn’t go to trial within a legally specified number of days, it is automatically dismissed in accordance with New York law.

Last Saturday, Santos allegedly used a 3-foot piece of metal to bludgeon five sleeping men in Chinatown, killing four and leaving one clinging to life.

Several court officers were stunned that the DA let Santos slide. Dennis Quirk, president of the state’s court officers union, blasted the Manhattan DA’s Office for giving Santos a free pass.

“Unfortunately attacks on court officers and police officers are not taken seriously anymore, even by the Manhattan DA’s Office,” Quirk said. “Criminals are doing this because they know there is no punishment.”

He added that crimes against law enforcement should be taken the most seriously.

“We are unable to comment because the cases are sealed,” a Manhattan DA spokesman said.

Santos, who faces multiple murder charges for Saturday’s massacre, has a lengthy rap sheet for violent crimes. He was free roaming the streets at the time of the attacks because a nonprofit group, Bronx Freedom Fund, had posted his bail while he was jailed for allegedly groping a young woman.

In another big break, a Brooklyn judge let Santos slide on a potential yearlong jail sentence after he violated a plea deal in a turnstile jumping case.

The groping and fare evasion cases were pending when he allegedly slaughtered the four sleeping homeless men.