Can you run?
A chainsaw is a deadly weapon that can severely injure, mutilate or kill you with a single touch. So if you are not 100% confident that you can beat the attacker easily, you should run. The weight of the chainsaw alone will ensure that the attacker will be slower than you. In addition the chainsaw is difficult to hold and will force the attacker in a certain body position that makes it difficult for him/her to pass through tight space (doors, windows, gates) or over obstacles. You can use that to your advantage when plotting your escape route.
Understand the attacker
Also most answer compare the chainsaw to a sword, it is a very different weapon and should not be treated like someone wielding a sword. The main difference is that the damage is done by the rotating chain and not by the impact of hitting you. Therefore the attacker just needs to simply point the weapon at you and come in contact with your skin to kill you.
In Hollywood movies chainsaw-killers tend to wield it around like a sword, but that is just for the show, a smart killer would just point it into your general direction, leaving you no moment where his 'guard' is down. This can tell you a few things about the intend of the attacker:
- If the attacker does wield it like a sword, there is a good chance that he has no clue what he is doing, you might be able to use that for your advantage.
- If he is making a show, he is not 100% ready to kill you. He is buying time to make sure he really wants this. You can use this to your advantage to negotiate or trick him to drop his guard.
- If he does simply point it at you, he has a real intend to kill you and probably knows what he is doing and will take the first advantage to slice you in half.
How to defend
Suppose you cannot run and are facing someone with a real intend to kill you, the first priority should be to stay alive. You cannot block the chainsaw as it will simply cut through your flesh and bones, so you must not let it touch you. Evading must be the highest priority.
A chainsaw usually has an emergency off system if the chains get stuck in something. So if you manage to trick the attacker to for example push the weapon in dense material that the chainsaw is unable to cut, it will turn off and probably will even be stuck. This would obviously be a good point to fight back. Once you hit him, he will probably not be able to pick up and activate the (for a fight) complicated mechanism to use it against you again.
A chainsaw as well has a system to prevent accidental activation, by forcing the user to push two buttons or grab it in a certain way to operate it properly. This forces the attacker in a certain position that makes it more difficult for him to move freely. In addition a chainsaw is very heavy. Unless you face Mr. Universum, there is a good chance that the attacker will loose balance and eventually loose grip on the handles if you can get him to swing it around, by moving left and right for example, or at least can cause him to hit obstacles with it, which might cause him to loose control over the weapon.
The inertia of the swing can give you a momentary chance for attack, but do not charge in unless you are 100% certain the attacker cannot use his weapon for the moment, as a simple tilt (which requires little strength) can bring back the blades in a position where they will kill you. If such a moment does not present, your best option is to tire the attacker until he gives up or makes a major mistake.
Summary
Your best chance to defend is to run. You second best chance is to force the attacker to swing the weapon around, in hope that he either gets stuck somewhere, looses grip, gets tired of wielding a very heavy weapon, or someone calls the police and you receive outside help. Basically the second options means: buying time.