A white supremacist has pleaded guilty to killing a black man with a sword as part of a racist plot that prosecutors described as a hate crime.

James Jackson admitted to fatally stabbing 66-year-old Timothy Caughman in 2017 after stalking a number of black men in New York City.

Jackson, who is white, told police he traveled from Baltimore to carry out the attack because New York is the media capital of the world.

He also said the slaying had been practice for further assaults on black people.

Jackson had been scheduled to stand trial on Wednesday. A judge had ruled that jurors would hear his detailed confession.

He faces life in prison when he is sentenced 13 February for his plea to murder charges.

Caughman, who was remembered as a gentleman and a good neighbor, was alone and collecting bottles for recycling when he was attacked from behind with a sword. He staggered, bleeding, into a police station and died at a hospital.

Jackson is from Baltimore and a veteran who served in Afghanistan. Family friends said previously that the allegations were out of line with how he was raised, in a tolerant and liberal middle-class family.

In a 2017 jailhouse interview with the Daily News, Jackson said he intended the stabbing as “a practice run” in a mission to deter interracial relationships.

He said he would rather have killed “a young thug” or “a successful older black man with blondes … people you see in Midtown. These younger guys that put white girls on the wrong path.”