Is it better to pay off a mortgage or invest?

Is it better to pay off a mortgage or invest?