Robert Pattinson is a hero to 4-legged friends for refusing to masturbate a dog for a movie scene ... so says PETA.

The actor told Jimmy Kimmel Thursday night the director of his latest flick, "Good Time," wanted him to shoot a scene in which he pleasured a pooch, but Pattinson drew a line in the sand and refused.

PETA is now praising Pattinson, saying the scene is both a form of mistreatment and "like child molestation."

The animal rights org refers to a story TMZ broke, involving a distressed dog that appeared to have been forced to swim in raging waters in the movie "A Dog's Purpose," saying, "PETA depends on actors and crew members to come forward when they see mistreatment."