Yes, it can.
There are varying ways to defend one human from another human attacking them.
For starters, a robot could remove the victim from the place of attack: pick up the victim and run away from the attacker.
A robot could simply stand between the attacker and the victim, and block the attack - let the attacker hit it, instead of the victim.
A robot could immobilise the attacker without harming them, such as by wrapping its arms around them to stop them hitting the victim.
If there was a weapon involved, like a knife or a gun, the robot could disarm the attacker by grabbing the weapon. If the attacker didn't let go of their weapon and the robot ended up harming the attacker, this would cause problems for the robot - and the level of problem would depend on the amount of harm caused.
There are many ways a robot can defend a human from being attacked without harming the attacking human.
However, if the robot was unable to stop the attack in any of the above ways, the robot might have to take more direct action. And, the robot would go as far as necessary to defend the victim - until it harms the attacker. At that point, the fact of actively harming a human outweighs the potential harm to the victim, and the robot has to deal with the "guilt". Many robots will simply shut down at this point. Some would become disoriented and require service. Only a very few highly advanced robots (like <PERSON> or <PERSON> or <PERSON>) would be able to deal with the harm they caused, by balancing it against the harm they prevented.
As far as I know, the scenario of a robot defending a human against another human's attack has occurred only once in any of <PERSON>'s stories. To describe it will require spoiling the end of 'Robots and Empire'. 44
If you haven't read that book and don't want the ending spoiled, you'll have to skip the rest of this answer. Sorry!
In that book, a couple of humans (Spacers) were conspiring to irradiate the Earth. They had different motives: <PERSON> wanted to irradiate the planet slowly, over centuries, merely to force the Earthpeople to leave the planet; <PERSON> wanted to irradiate the planet quickly, over only a decade or two, which would kill billions of Earthpeople who would be unable to leave the planet in time.
Two robots, R. Daneel Olivaw and <PERSON>, are trying to prevent this. They arrive on the scene and find <PERSON> pointing a blaster at <PERSON> (trying to convince <PERSON> to do things <PERSON>'s way).
Quicker than the eye could follow, an arm stretched out to seize <PERSON>'s wrist, paralysing it with pressure, and the blaster was gone.
<PERSON> said, 'I apologize for having had to inflict pain on you, Dr <PERSON>, but I cannot allow you to hold a blaster pointed at another human being.'
Simple as that: a robot caused pain to one human being to prevent him hurting or killing another human being. Admittedly, Daneel was a very advanced robot. More simplistic robots might have suffered a brain-freeze after having caused pain to prevent harm.
Later, <PERSON> puts <PERSON> into a coma (<PERSON> has telepathic powers - long story!) when <PERSON> explains that he wants to kill Earthpeople. And, <PERSON> suffers no ill effects from that action - but he's another advanced robot. In fact, he's the robot who invents the Zeroth Law of Robotics: "A robot shall not harm humanity or, through inaction, allow humanity to come to harm." (He does "die" from something else he chooses to do later, because he's not sure if he made the right choice for humanity.)
These are two robots who inflicted pain and harm on a human to prevent him: killing a visible and present human; killing many humans, neither present nor visible at the time. 516