Are Paul and James contradicting each other? The answer is No.
Paul and James are talking to two different groups of believers. Paul was dealing with Jewish believers who were trying to force gentile converts to keep all of the law of Moses in order to be justified. Paul responded to this by saying that people can’t earn salvation; rather, it comes as a free gift from God. However, James is dealing with new converts who have come into the church believing that since they’re justified by faith, obedience doesn’t really matter.
In order to understand James, we need to read the verse that follows verse 21: “Do you see that faith was working together with his works, and by works faith was made perfect?” (James 2:22 -NKJV). Faith, then, works together with works. How? The word “perfect” in this sentence means complete. When used in the sentence, it means Abraham’s works by faith were made manifest, that is, they gave evidence to his faith. In other words, his actions proved he was justified! We are saved by faith alone but faith will manifest itself in good works.
The Bible is filled with references to how important good actions are. It’s not a sin to do good—it’s not wrong to stop sinning. “Likewise also the good works of some are manifest beforehand; and they that are otherwise cannot be hid” (1 Timothy 5:25). This passage shows us that the deeds of the saved are evident because they are good. You’ll know a saved person by his fruits. 1 Timothy 6:18 reiterates, “That they do good, that they be rich in good” deeds.
Also, we read “For we are His workmanship, created in Christ Jesus unto good works, which God hath before ordained that we should walk in them” (Ephesians 2:10). And Paul adds, “In all things shewing thyself a pattern of good works: in doctrine shewing uncorruptness, gravity, [and] sincerity” (Titus 2:7); “That the man of God may be perfect, throughly furnished unto all good works” (2 Timothy 3:17). Notice that the same person who wrote the above verses is the apostle Paul who has written our starting verse Romans 3:26.
In His service,