ELIZABETH, N.J. — Two cups of coffee ended life on the run for an Internet sensation known as Kai the hatchet-wielding hitchhiker.

An employee at a Starbucks in Philadelphia is credited with recognizing 24-year-old Caleb “Kai” McGillvary, whose fledgling celebrity took a turn toward notoriety when authorities announced this week that he was wanted in the beating death of a New Jersey lawyer three times his age.

The unlikely pair met amid the neon lights of New York City’s Times Square over the weekend and headed back to the squat brick home of 73-year-old Joseph Galfy Jr. on a quiet cul-de-sac in suburban Clark, N.J., authorities say.

On Monday, Galfy was found beaten to death in his bedroom, wearing only his socks and underwear. McGillvary was arrested Thursday shortly after leaving the Starbucks and charged with killing Galfy.

McGillvary gained a measure of fame in February after intervening in an attack on a California utility worker. In an interview viewed millions of times online, he described using a hatchet he was carrying to repeatedly hit a man who had struck a worker with his car, fending off a further attack, and thus became known as “Kai the hatchet-wielding hitchhiker.”

Galfy’s funeral was held Friday in a small stone chapel in Warren, N.J. He was buried in East Hanover.

The victim’s sister-in-law, Diane Galfy, said at her home that “he was a very well-respected man. That’s what we want people to know,” she said. She said her husband didn’t want to talk and her children were devastated.

Galfy was a lawyer who in recent years handled land use and domestic violence cases, according to Union County Prosecutor Theodore Romankow, whose office is prosecuting McGillvary.

“He was just a nice man, a gentle man, well-regarded in the community,” Romankow said.

In addition to his law practice, Galfy was the attorney for the planning board in Green Brook, N.J., and played drums in a wedding band.

Authorities said McGillvary was arrested Thursday evening after he walked into a Starbucks near a bus station in downtown Philadelphia and ordered two coffees. The woman who served McGillvary recognized him and alerted her manager, who called the police.