The way to avoid legalism is to believe that, as the Law teaches, only the perfectly righteous may be admitted into heaven. This counterintuitive premise accomplishes two things in a single blow: it crushes legalism and clarifies the meaning of grace.
First, it crushes legalism because legalism cannot get off the ground unless the standard has first been lowered. But if the Law requires perfect righteousness, clearly the half-baked, imperfect obedience promoted by legalism will not do.
Second, it clarifies the meaning of grace. Grace is that God provides and accepts the imputed righteousness of Christ, in place of our own
inherent righteousness demanded by the Law, as the righteousness by which the unrighteous can attain heaven. Now that’s grace! The true Gospel, then, presupposes the Law as its antithetical counterpart. Otherwise grace is no longer grace."