Anthony Torres poses for a photograph at his brother’s home in Atco, N.J., on Monday. (Matt Rourke/AP)

Anthony Torres was on his way to see family. He was ready to forget about the last few weeks.

He was also about to become an instant Internet sensation, the subject of unsparing insults and pitiless social media posts. In the three days to come, his story would reveal the basest instincts of the online era — and then, later, the best.

But riding a train out of New York City bound for his brother Thomas’s house in Atco, N.J., Torres didn’t know any of that yet.

He just knew he needed a shave.

So the 56-year-old took out a razor and cream and shaved his face right there in his seat on the Northeast Corridor train Thursday evening.

Unbeknownst to Torres, a fellow passenger took out his phone and filmed Torres grooming. He then posted it to Twitter that night. Likes, retweets and responses ensued — tens of thousands of them.

The online condemnation of Torres was swift and cruel. He was called “an animal,” “nasty” and “a gross person.” One New Jersey media outlet tweeted, “A guy was caught shaving on an @NJTransit train and we can’t look away.”

But in an interview with The Washington Post, Torres said the commenters and the cameraman didn’t know him, and they didn’t know what he’d been through.

“They don’t know the real me,” Torres said.

In the weeks before that train ride, Torres had bounced between Atlantic City and Manhattan. He slept in homeless shelters and beneath bridges. In both cities, he said, he was mugged and robbed. The shelter in New York didn’t have enough room for him, so on Thursday, he decided to go someplace that felt like home.

“It’s been rough,” Torres said. “There were a lot of nights where I laid under the bridge and cried.”

He said he phoned another brother for help, and his sibling sent Torres money for a train ticket.

On the New Jersey Transit train out of Penn Station, Torres said he felt the weight of a couple of tough weeks, the latest in a hard life. He was hungry. He hadn’t had a chance to shower, and he hadn’t shaved in days.

On the train, Torres said, “I felt dirty.”

He wanted to look good for his brother’s family, he said, he wanted to look “presentable.” That impulse, a few strokes of the razor and a flick of shaving cream onto the floor, were enough to vault Torres into Internet infamy.

When a niece showed Torres the video, he was first embarrassed and then scared he’d get in trouble. He told his family he’d never ride a train again.

Of course, Torres didn’t ask for the attention — the video of him shaving has already been on TV across the country, and he has fielded calls from international media outlets. The Internet has proved itself a fickle and malicious machine that pounces on unwitting viral sensations like Torres, and, before him, “Gary from Chicago,” who appeared during the Oscars, and Ken Bone, who was at the second presidential debate between Hillary Clinton and Donald Trump.

But occasionally, it shows a capacity for kindness.

On Monday, after the Associated Press first reported on the man behind the meme, some who shared the video expressed regret for spreading the derision without understanding Torres’s experience.

One New Jersey journalist wrote on Twitter that the episode should make social media users rethink “the culture we’ve created in which we boil everything down to dumb viral video.”

Even the passenger who filmed Torres expressed regret for the post that started it all. “I never intended any harm by taking or posting this video,” tweeted Pete Bentivegna, who had previously told NJ.com that Torres shaving on the train was “right up there with the strangest things I’ve seen fore sure.”

On Tuesday, Bentivegna posted a message that said he had licensed the video and planned to donate all proceeds to Torres and his family.

But the biggest show of support came from Jordan Uhl and the GoFundMe page he set up after seeing the video and reading the Associated Press story. As of Tuesday evening, the fundraiser, titled “Anthony Torres Assistance Fund,” had raised more than $20,000 toward a $25,000 goal. Uhl, who works at the Washington-based advocacy firm MoveOn.org, said he’s in contact with the Torres family.

“Let’s get him as comfortable as we can because so many people in this country live paycheck to paycheck and it’s really, really difficult for people to get ahead,” Uhl said in an interview with NJ.com.

Taken side by side, the comments from contributors to Uhl’s GoFundMe page and respondents to Bentivegna’s video of Torres lay bare the Internet at its peak and pit.

“And then the pig slams the shaving cream on the floor – so gross,” wrote one Twitter user.

Meanwhile, on the charity platform, benefactors posted messages like this: “I’m sorry that you have been the subject of such cruelty. Your bravery does not go unnoticed. I hope this donation helps you get to a better place in life because you deserve it. God bless you ♥”

Thomas Torres said he and his four other siblings have tried to help their brother his whole life. He has health problems that stem from two strokes, and he has had trouble keeping a steady job. But, in a strange twist, Thomas Torres said, this moment — which could have been painfully embarrassing for his brother — may change Anthony’s life.

“He’s gone through hell his whole life,” Thomas Torres told The Washington Post. “I think this is an eye-opener for him, to see that so many people care about him.”

Anthony Torres is now staying with his brother Thomas, who said he’d help Anthony manage the money that people all over the country are donating to him, though they don’t yet have plans for it. Thomas said the past couple of days show that people shouldn’t be so quick to criticize.

“This here does prove that you don’t judge a person until you really know their background,” Thomas Torres said. “It’s the truth. You have to look at all that happened to him before he even got on the train.”

From his seat on that commuter train, Torres traveled much farther than the 80-some miles between Manhattan and Atco. But the last few weeks are finally behind him. And he’s with family now.