A career criminal claiming to be a cousin of Freddie Gray — the Baltimore man whose death in police custody sparked weeks of civil unrest – socked a plainclothes cop in the face while bolting out of a Brooklyn subway station Thursday, police sources said.

An officer spotted alleged farebeater Marsaay Gray, 26, walking through an emergency exit at the Myrtle-Willoughby Ave. G train station about 3:45 p.m., sources said.

When the cop approached him, Gray took off – but he didn’t get far.

He allegedly slugged the officer in the face before being pepper-sprayed and tackled to the ground, police sources said.

The cop suffered a cut inside his mouth and pain, redness and swelling to the left side of his face, sources said.

Gray told arresting officers that his cousin was Freddie Gray, the black 25-year-old who suffered a fatal spinal cord injury after he was arrested by Baltimore cops.

The injured officer and Marsaay were taken to nearby hospitals.

Marsaay, who lives in East New York, was held on $3,500 bail following his arraignment Friday in Brooklyn criminal court.

He’s charged with assault, resisting arrest, theft of services and attempted assault.

Marsaay’s attorney didn’t return messages.

Sources said his rap sheet includes 26 arrests dating back to 2006, mostly for turnstile jumping and drug and weapons possession.

In a May 1, 2015 Facebook post, Marsaay paid homage to a “Freddy Gray.”

“I lost a good family member he was a great and loving guy he was out going and people all over love him Freddy gray,” he wrote. “He treated people with respect just like how he wanted to be treated with respect.”

Freddie Gray’s death kicked off weeks of mass rioting and looting in Baltimore and elsewhere in the nation by protesters calling for the prosecution of the six cops involved.

The officers were criminally charged but eventually all were acquitted.