As a person may act wrong by following a wrong sense of duty, so nature may sometimes prevail, and lead him to act right in opposition to it.
 Adam Smith, The Theory of Moral Sentiments (1759). copy citation

Context

“Such as are our sentiments for the unhappy Seid and Palmira, such ought we to feel for every person who is in this manner misled by religion, when we are sure that it is really religion which misleads him, and not the pretence of it, which is made a cover to some of the worst of human passions. As a person may act wrong by following a wrong sense of duty, so nature may sometimes prevail, and lead him to act right in opposition to it. We cannot in this case be displeased to see that motive prevail, which we think ought to prevail, though the person himself is so weak as to think otherwise. As his conduct, however, is the effect of weakness, not principle, we are far from bestowing upon it any thing that approaches to complete approbation.” source