Paul's epistle to the Galatians is essentially a polemic against Judaizers. He is concerned throughout about those who would seek to be justified by "works of the law." For Paul it is absolutely imperative to recognize that justification (being counted righteous) is not by "works of the law," but is a status received by God's declaration, which in turn is founded on Christ's having died for us, and is received by faith in that work of Christ.
However, many read into this certain presuppositions that I think hinder a proper understanding of Paul's point. The first of these is that "works of the law" is essentially a cipher for any good thing that a person does. This simply doesn't hold up. It is clear that Paul has in mind particularly those things which marked out the Jewish people as distinct, most especially circumcision. Time and again he comes back to this noting that Titus was not forced to be circumcised (2.3), that Peter was wrong to create divisions along the lines of circumcision (2.11-14), that by accepting circumcision (which was apparently being urged on the Galatian Christians) they would cut themselves off from Christ (5.2-3), that he certainly does not preach circumcision (as must have been rumored) (5.11), and finally that he wished those who were urging it on them would go all the way and castrate themselves (5.12). Now this is not to say that Paul believed that one could receive initial justification (that is the declaration of righteousness) by doing good deeds. It is simply to recognize the particular polemical force of Paul's argument. His argument is essentially that there are those who would have you become Jews (i.e. be circumcised, celebrate the traditional feast days, etc.), in order to inherit the promise, and they must be rejected. The promise is received by faith in Christ.
But this brings us to the second assumption that is made, which is that justification can be taken either as the sum total, or as the only relevant, aspect of right relationship with God. That is, having already conceived of works of the law as referring to any works done by the Christian, many go further and say that not only are these works not relevant to one's being declared righteous and a son/daughter, but they are not relevant to one's ongoing relationship with God. While I agree that (initial) justification is not on the basis of anything we have done (although I dispute that that is Paul's main point in Galatians), it does not follow that the things we do have no bearing on our life of faith and relationship with God. Indeed, for this thesis to work we would have to chop off the majority of chapters 5 and 6 where Paul goes into ethics and remind us what kinds of people inherit and don't inherit the kingdom vis-à-vis there works.
In 5.14 Paul essentially does a bit of wordplay with his own prior use of the word "law" (as I understand it), saying, 'fine, if you want to be righteous by the works of the law, no problem. The law is fulfilled when you love your neighbor as yourself. So do that!' Now of course Paul is not here saying that one can be declared righteous before God simply by loving others. But he is saying, that a proper concern for law-keeping with regard to maintaining a right relationship with God is fine, but let's talk about what we mean by law. The essence of the law, that which abides even now, when we are not under the law as tutor, the "Law of Christ"(!), is fulfilled when we, by the Spirit, love one another. There's your law-keeping.
But more than all that, it simply is evident that Paul is not arguing in Galatians for the idea that our actions, our behavior or 'works' have nothing to do with our relationship to God, or even our ultimate fate. In 5.19-21 Paul lists a number of actions (i.e. works) and warns us that those who do such things will not inherit the kingdom. Paul is not here contradicting himself. He has written a letter to a beleaguered church, harangued by Judaizers who, because they don't want to suffer the shame of the cross, are trying to convince these new Christian converts to accept circumcision and Jewish law keeping along with Christ. To them he says, 'No!' These are the children of Abraham, children of the promise, and they are adopted heirs by faith. But to those children, to those heirs he says, 'do not use your freedom from the childish tutor-law as an excuse to ignore the law of Christ. Walk by the Spirit, who leads you as grown-ups, knowing that if you walk in gross sin and high-handed rebellion to the will of your Father you will be written out of the will and fail to inherit the kingdom.'
"For you were called to freedom, brothers. Only do not use your freedom as an opportunity for the flesh, but through love serve one another. For the whole law is fulfilled in one word: “You shall love your neighbor as yourself.” But if you bite and devour one another, watch out that you are not consumed by one another.
But I say, walk by the Spirit, and you will not gratify the desires of the flesh. For the desires of the flesh are against the Spirit, and the desires of the Spirit are against the flesh, for these are opposed to each other, to keep you from doing the things you want to do. But if you are led by the Spirit, you are not under the law. Now the works of the flesh are evident: sexual immorality, impurity, sensuality, idolatry, sorcery, enmity, strife, jealousy, fits of anger, rivalries, dissensions, divisions, envy, drunkenness, orgies, and things like these. I warn you, as I warned you before, that those who do such things will not inherit the kingdom of God. But the fruit of the Spirit is love, joy, peace, patience, kindness, goodness, faithfulness, gentleness, self-control; against such things there is no law. And those who belong to Christ Jesus have crucified the flesh with its passions and desires."
(Galatians 5:13-24 ESV)