What shall we say then that Abraham our father, as pertaining to the flesh, hath found?
For if Abraham were justified by works, he hath whereof to glory; but not before God.
For what saith the scripture? Abraham believed God, and it was counted unto him for righteousness.
Now to him that worketh is the reward not reckoned of grace, but of debt.
Seest thou how faith wrought with his works, and by works was faith made perfect?
And the scripture was fulfilled which saith, Abraham believed God, and it was imputed unto him for righteousness: and he was called the Friend of God.
Ye see then how that by works a man is justified, and not by faith only.
The apparent contradiction is based on a misunderstanding of the actually clear statements of the Scriptures. In Romans (as well as especially also in Galatians) it is clearly stated by the apostle Paul that man is made righteous before God on the basis of faith or believing and not on the basis of his own fulfillment of the works of the law. The greatest example perhaps for this truth is Abraham, and the record of God's Word about him is given as illustration, to whom righteousness was accounted on the basis of his believing God. The contrast in the records of the New Testament Epistles is between the righteousness which God grants on the basis of faith or believing on Christ vs. the righteousness which some endeavoured to have by means of the works of the Law. Now, what was the case with Abraham - since one place attributes righteousness to his faith or believing, and another seems to say that justification was not by faith alone?
Now, in James "works " are mentioned, which Abraham did and which worked together with his faith (in Verse 22). These works however were of course not "works of the Law ". It must be noted that at the time of Abraham the Law had not even been given by God with those works prescribed in it. What is called "works" here are simply the actions, the deeds that Abraham did in agreement with and on the grounds of his believing. This section in James is not speaking about the works of the Law versus believing, it is solely about believing! It shows that "believing God", as Abraham did, manifests itself in actions when and where these are required. Abraham's believing, his trust in God as concerning the promises God had given, is shown forth and proven in his actions, his deeds, his works. This is true of us today as well, otherwise it would only be "dead faith [believing]" (cp. James 2:17).
Abraham was accounted righteousness by believing, not by works of the Law! His believing and trust in God was documented and alive in his works, i.e. in his actions which he did in trusting God