That's very easy. James and Paul do not contradict each other. Keep in mind that one verse cannot stand alone in contradiction to many other passages in scripture. James only focuses more heavily on the results of true faith. True faith with the indwelling of the Holy Spirit will naturally produce the right actions. Notice results of true faith. The actions are simply proof of true faith. It still remains that it's the faith that resulted in salvation with the indwelling of the Holy Spirit. The right deeds followed that true faith and were the result of it. The Greek word in your verse 22 means to complete as in finishing a race. In other words the "win" at the end of the race was the result of running the race.
Paul clearly understood that by focusing on true faith in Christ and the indwelling of the Holy Spirit right deeds would naturally follow. Those who are telling Christ that they cast out demons etc were doing it of their own volition for their own glory or hope for reward. Those who were saved and asked Jesus when they had done those things to Him didn't even realize because it was a natural act due to the indwelling of the Holy Spirit.
James is broadly talking about our Christian walk and our faith manifest in our works. What you have to see in the difference in the focus of the two is that James points out that we are not saved by faith alone but rather our faith shown through our works. Note that there is an indivisible physical element of this faith walk that too many Protestants deny.