A cruel joke that went viral led to an outpouring of support for a homeless man in Ocean County, New Jersey, who was put up at a hotel and surprised with gear from the San Francisco 49ers, according to a homeless advocate who helped him.

Ronald Leggatt, 65, was homeless and living in a baseball field dugout in Lakewood, New Jersey, last month when he was approached by a young man who paid him $5 to pour coffee over Leggatt's head.

"I was so broke, I needed the money, to be honest with you," Leggatt said. "My friend came by and helped me."

Another person snapped photos of Leggatt moments later and posted them on Facebook with a description of what happened. Leggatt’s story went viral and attracted the attention of people across the country, who helped him with donations used to put him up in a hotel, according to a GoFundMe page set up to help him.

"Somebody meant it to mock Ron as a homeless person," said Steven Brigham, a homeless advocate. "But it turned around where Ron got housing because of the situation."

Leggatt, who was wearing a weathered San Francisco 49ers jacket in the viral photo, soon gained the attention of the team itself, according to Brigham.

Brigham said the 49ers reached out to him wanting to help. He surprised Leggatt on Friday with a box full of 49ers gear, including a brand new jacket.

"Unbelievable," Leggatt said. "From California! That’s just unbelievable! Best thing that ever happened!"

Brigham told NBC10 he believed what was initially an unfortunate incident ended up being a blessing in disguise.

"There’s still some compassion here in this country," Brigham said. "Ron might have died this winter in that dugout if he wasn’t rescued by this situation."

Roger Hacker, a spokesman for the 49ers also sent a statement to NBC10.

"The situation that brought Mr. Leggatt's story to our attention was certainly unfortunate and we wanted to make sure he knows we consider him a valuable member of the Faithful," Hacker wrote. "We hope we were able to bring a smile to his day."