DJ Megatron’

The man accused of firing a fatal gunshot into the chest of DJ Megatron in a botched robbery almost two years ago took a plea Tuesday and will spend the next 21 years behind bars, prosecutors said.

William Williams, 22, faced trial in Staten Island on a second-degree murder rap and, if convicted, a potential prison sentence of 25 years to life. He instead pleaded guilty to first-degree manslaughter.

“After careful reflection and thought, my client decided this was in his best interest,” said Williams’ lawyer, Mario Gallucci.

The 32-year-old disc jockey, aka Corey McGriff, was a former radio personality on Hot 97 and a regular on BET’s “106 & Park.”

Megatron was about a block from his Stapleton home when he was slain in March 2011. Williams and an accomplice, Richard Cromwell, had been stalking him, seeing the rising star in the hip hop world as a good mark, prosecutors said.

When they made their move, Williams blasted Megatron, and the duo made off with a wad of the deejay’s cash and a wristwatch given to him by his daughter, then just 11 years-old.

Both men were arrested and charged with murder, robbery and criminal possession of a weapon. Cromwell’s next court date is Feb. 27, records show.

Share