Police have arrested a man in the murder of a McDonald’s worker — thanks to the suspect’s inability to stay unplugged.

Stabbing victim Adam GarciaFacebook

Rafael Gonzalez, who has been living in a New York City homeless shelter for the past year, used the free Wi-Fi at the Kingsbridge eatery on the same day he is suspected of stabbing Adam Garcia, 28, sources said.

Cops tracked down the man’s family in New Jersey — and he turned himself in Wednesday when he learned police were hot on his trail, the sources said.

Gonzalez arrived at the 50th Precinct station house with a lawyer at around 11 a.m. He had not been charged as of Wednesday night.

Garcia had just gotten off work at 4:30 a.m. Monday when he spotted a homeless man heading to the bathroom to wash himself, as the vagrant did several nights a week, cops and sources said.

The man had been lounging inside the eatery, at 5765 Broadway near West 236th Street, for hours, the sources said.

Fed-up with him, Garcia said, “This is not your apartment,’’ according to sources.

Garcia then headed to the door with a female co-worker, and the man followed him outside, the sources said.

Their argument escalated, and the vagrant stabbed Garcia in the chest and the throat with a knife.

As the killer fled, Garcia stumbled back inside the eatery and told co-workers what had happened before collapsing. He died a short time later.

After the murder, sketches of the suspect were posted around the restaurant.