An emotionally disturbed parolee tried to run off a Brooklyn subway car with a 4-month-old baby, but was fought off by the frantic mother, grandmother and a good Samaritan, authorities said.

Rafael Martinez, 30, approached the family aboard a J train near the Alabama Avenue station in Cypress Hills at around 11 p.m. Sunday, cops said.

The mom, Yubarbina Peña, 21, was with her mother, Carpio Peña, 42, her 3-year-old niece and 4-month-old daughter when Martinez inquired about the toddler.

Martinez, a gang member on probation, then plopped himself down on the seat too close to the 3-year-old, prompting the women to shoo him away.

Martinez became agitated and allegedly ripped the portable seat from infant Barbie Montero’s stroller.

He then took off for the door with the seat in his hands as the train entered the station, authorities said.

“Let me go! I want the baby,” Martinez yelled in Spanish, according to police sources.

But the mom and grandmother desperately held on to the seat, fighting Martinez in a tug of war that jerked the baby back and forth.

During the struggle, another straphanger who saw what was happening rushed over. She grabbed Martinez and pinned him to the train seat, helping the women gain control of the baby.

The woman who witnessed the attempted kidnapping then held Martinez down until police officers arrived a short time later and arrested him, sources said.

Martinez was charged with attempted kidnapping, acting in a manner injurious to a child and possession of a controlled substance for a small amount of cocaine he was carrying in his wallet, police said.

Martinez has more than 20 prior arrests, including several for drug possession, assault and robbery, the sources said.

He is also a P-Stone Bloods gang member who is on probation until 2018, police sources said.

He tried to kill himself on two occasions last year, and this past February told cops who were responding to a call that he had seen God.

Nobody answered the door at the family’s basement apartment in East New York.