A razor-wielding attacker slashed two straphangers without uttering a word on a Manhattan-bound subway train in Brooklyn on Tuesday, police said.

The unidentified 29-year-old man, who was wearing a denim jacket and Timberland boots, stepped onto the C train at Rockaway Avenue in Bedford-Stuyvesant at around 3:30 p.m., according to law-enforcement sources.

Without warning, he stabbed 32-year-old Oneal Mendez once on the top of the head with a boxcutter blade, the sources said.

His next victim was 22-year-old Matthew Ruff, who had witnessed what happened and started moving to another train car.

But Ruff couldn’t avoid the attacker, who slashed him once, again on top of his head, and then ran off the train when it pulled into the Ralph Avenue station.

“It was random,” a law enforcement source said. “I don’t know why — it’s so hard to understand. No words, no quotes, he just slashed them.”

The attacker fled, but was soon caught at Rockaway Avenue and Fulton Street. A razor was recovered at the scene.

After complaining about pain, the suspect was taken to Brookdale University Hospital. He had not been charged as of late Tuesday night.

The two victims, who both live in The Bronx, were also transported to Brookdale. Both are expected to survive.

“I saw the guy with old jeans and blood,” said Michael Lopez, 35, who works at a barbershop across the street from the station. “He was covering his face and he was on the phone. His face was red. He was crying.”

Another witness, Kelly Patton, 42, said, “Everyone was confused.”

“The [train] dispatcher said we need a doctor or a nurse,” she said. “I just tried to stay calm. And the conductor said something about a person on the train.”

Cops at the hospital were waiting for the victims to be treated before they could interview them, sources said.

Local residents were disturbed by the unprovoked attacks.

“It’s awful,” said Ebony, who declined to give her last name. “At this time of day, at least there’s no kids out here. I never heard of anybody getting stabbed.”

“I thought it was a love triangle,” said Marvin Escott, 47, an off-duty MTA employee.

“Usually this stuff is domestic. But it was random? That’s crazy. I think it’s very sad and unfortunate. He’s probably an EDP.”

Additional reporting by Tina Moore