In Romans 2, Paul says the following:
[God] will render to each one according to his works: to those who by patience in well-doing seek for glory and honor and immortality, he will give eternal life; but for those who are self-seeking and do not obey the truth, but obey unrighteousness, there will be wrath and fury. There will be tribulation and distress for every human being who does evil, the Jew first and also the Greek, but glory and honor and peace for everyone who does good, the Jew first and also the Greek. For God shows no partiality. (Rom. 2:6–11)
On the face of it, this is about as clear as someone can get when saying that everyone—including believers—will be judged according to their works. The trouble is that this is part of an argument Paul is making for the conclusion that people are justified by faith apart from works. As he says in chapter 4:
For what does the Scripture say? “Abraham believed God, and it was counted to him as righteousness.” Now to the one who works, his wages are not counted as a gift but as his due. And to the one who does not work but believes in him who justifies the ungodly, his faith is counted as righteousness, just as David also speaks of the blessing of the one to whom God counts righteousness apart from works… (Rom. 4:2–6, emphasis added)
Out of a desire to preserve the Pauline doctrine of justification by faith alone, some have suggested that we understand Paul to be speaking in hypotheticals when he says that God will give eternal life “to those who by patience in well-doing seek for glory and honor and immortality.” According to this “hypothetical reading,” Paul is reasoning as follows: if someone were perfectly good then they would earn eternal life, and conversely if they didn’t then they would earn wrath and fury. Since everyone has sinned (3:9), it follows that the first option is not available to anyone, and therefore we all stand condemned (3:19–20). Thus, the only way for us to be right with God is for him to introduce a third option, whereby we are justified by faith wholly apart from works.
There are two problems with this proposal. First, it undermines Paul’s entire point in Rom. 2:6–11. By positing some third option, it is saying that for some people God will not render to them according to their works, which is exactly what Paul is denying. He raises his point in opposition to the position of some of his fellow Jews, that God would treat them favorably not on account of their works but on account of them having the law and circumcision (2:13, 25). Paul’s counterpoint here is that such a scheme would make God partial, and since both parties agree that this would contradict God’s justice, it follows that there cannot be some third option. Thus, God renders to everyone according to their works, both Jew and Gentile. It makes no sense, then, to suggest that Paul eventually goes on to suggest a third option of his own!
The second problem with the hypothetical reading is that it is motivated by things that Paul doesn’t actually say. Paul does not say that those who seek honor and glory and immortality will earn eternal life, only that God will give it to them. And Paul does not say that God will only give it to them if they do so perfectly.
So, then, we should reject the hypothetical reading, and accept that Paul sees no contradiction between justification by faith and judgement according to works. What remains to be done, then, is to explain what judgement according to works is about if it isn’t about earning eternal life through perfect obedience.
Schreiner offers the following suggestion:
Human works cannot be the basis of right standing with God since all sin and all fall short of the glory of God. The saving righteousness of God given to us in Jesus Christ is the foundation and basis of our right standing with God. But if works aren’t the basis, what are they? They are surely necessary, for one is not saved without them. But they can’t be the necessary basis since God demands perfection and all fall short of what God requires (Rom. 3:23). It seems legitimate to say that works are the necessary evidence and fruit of a right relation with God. They demonstrate, although imperfectly, that one is truly trusting in Jesus Christ. (Emphasis original)
Piper also suggests something similar:
“According to works” means God will take the fruit of the Spirit (Galatians 5:22) and the “good deeds” by which we let the light of our faith shine (Matthew 5:16), and he will accept them as corroborating evidence of our faith. His sentence of acquittal will not be because we are not guilty. It will be because Christ bore our guilt. The place of our works at the judgment is to serve as corroborating evidence that we did indeed put our trust in Christ. Therefore when we are acquitted and welcomed into the kingdom it will not be earned by works but it will be according to works. There will be an “accord” or an agreement between our salvation and our works.
This suggestion seems good to me, so long as we don’t lean too heavily on the notion of “evidence.” Evidence is a way we come to know about reality, but works are more closely related to faith than this. To see what I mean, consider the analogy of a tree and its fruit, which is used in connection with this question (Matt. 7:15–20; 12:33–37; Luke 3:9; 13:6–9). The fruit that a tree produces is not merely evidence for the kind tree it is, but something that characterizes the tree. That is, it doesn’t merely help us to know about the tree, but is part of what determines the kind of tree it is. This characterization happens independently of anyone knowing anything about the tree. Likewise, then, works do not merely provide evidence for our faith (although they also do that), but they characterize it. They are part of what determines the kind of faith we have, and therefore whether the faith we have is something that can justify us.
Another reason not to lean too heavily on the notion of evidence is that it’s difficult to see why God would need evidence in the first place. Evidence is necessary in human affairs because we don’t know how things really are in themselves. But God knows reality exactly as it is, and searches our hearts directly (Luke 16:15, Rom. 2:15–16). This same concern does not apply to the suggestion that works characterize our faith, since this characterization is part of the reality known by God rather than something extra needed by God to know the reality.
In fact, it’s not only faith that is characterized by our works, but any orientation of our heart. If we hate God, or see him as someone to manipulate, or use him to look good in front of others, or whatever, the orientation of our heart will reveal itself in the way we live our lives. In general, then, our works characterize our hearts. The upshot of this is symmetry (or impartiality) in God’s judgment: God renders to each according to their works, because their works characterize their fundamental orientation to life with God. In order to make eternal life our own (Phil. 3:12), we must not only have faith in God, but this faith must be of the right kind, determined by our works.
Now, I recognize that it may sound a little strange to say that there are different “kinds” of faith, but this is an idea found throughout the New Testament. Jesus speaks of people who trust in him as Lord and even prophecy in his name, but who are rejected because they are “workers of lawlessness” (Matt. 7:21–23; 25:31–46). Elsewhere, he assumes that proper faith in him will have good works alongside it (John 5:24–29). James contrasts a faith that has works with a faith that doesn’t, and says that only by the former will anyone be saved (Jas. 2:14–26). Paul says that if you have faith but not love then that faith is nothing (1 Cor. 13:2), and elsewhere that what counts is faith working through love (Gal. 5:6). So, there are different ways we can have faith, and not all ways are equally capable of making us right with God.
So, then, in the final judgement we are justified by faith, but whether or not we have the kind of faith that justifies is determined by the way it manifests itself in our works. It is not that we need to do this or that particular thing, accumulate enough good points, or even live a perfect life in order to be right with God. Nor do we earn our salvation by our works—we are justified by faith as a gift from God. Nevertheless, the faith that justifies is characterized by love, so that if the love isn’t there then neither is the proper kind of faith—there might still be some other kind of faith, but not the kind that Paul has in mind when he talks about justification. In this way, then, God can judge us according to works while at the same time justify us by faith.
The practical outworking of this is found throughout Paul’s letters, and indeed all of scripture: don’t grow weary in doing good, because in due season you will reap eternal life (Gal. 6:9; cf. 2 Thess. 3:13). Continue to work out your salvation until the very end (Phil. 2:12). Practice self-control, to ensure that you are not disqualified from the race (1 Cor. 9:24–27; 2 Tim. 2:3–6). Pursue righteousness that you might take hold of eternal life (1 Tim. 6:11–16, Phil. 3:12). The wording varies, but the underlying point remains the same: make every effort to ensure that your faith is characterized by good works, because you can’t be saved through any other kind of faith. At the same time, we are encouraged by the fact that God works in us by the Holy Spirit to both believe and do good works. Again, there are various ways this is articulated: walk by the Spirit and not by the flesh (Rom. 8:13; Gal. 6:8). God has poured love into our hearts by his Spirit (Rom. 5:5). God has prepared good works for us to do (Eph. 2:10). And God works in us to will and work for his good pleasure (Phil. 2:13).
As with justification by faith and judgement according to works, it’s tempting to cling to one of these and ignore the other, but this will inevitably skew the biblical teaching. Those who ignore God’s role will fail to be properly encouraged to rely on him, while those who ignore our role will fail to be properly motivated by the warnings and exhortations to do good works.
Returning to Paul’s words in Romans 2, we see that there is no need to resort to a hypothetical reading in order to make sense of them. In the first option, he describes those who do not grow weary in doing good (“by patience in well-doing”) as they pursue a life pleasing to God (“seek for glory and honor”) that they might live with him (“he will give eternal life”). In what follows, Paul does not argue that sin has made this first option impossible, leading God to introduce some third option. Rather, he explains that God has made this first option accessible even to sinners, by justifying all who have faith in Jesus. Thus, so long as our patience in well-doing proceeds from faith, then our pursuit of life with God will not be in vain.
(Edited 29 Aug 2021: Added final paragraph.)
 Note that 2:6–11 is a chiasm, with the point about God being impartial matching up with the point about him rendering each according to their works.
 Thomas R. Schreiner, “Justification Apart From And By Works: At The Final Judgment Works Will Confirm Justification,” in The Role of Works at the Final Judgment (Counterpoints: Bible and Theology), ed. Alan P. Stanley (Grand Rapids: Zondervan, 2013).
 In this passage, Jesus says that those who do good will not come into judgment. Clearly, he is using the word “judgment” in a negative sense, rather than the neutral sense that we’re using in this post. The fact that these people’s good works factor into their receiving eternal life means that they’re being judged in the sense that we’re using it here.