I just read about this subtle but interesting distinction in John Kleinig's 'The Concept of Desert'. Basically, entitlement derives from our relation to some set of institutional rules, whereas genuine desert is pre-institutional, and instead reflects our intrinsic merit. So, for example, a hard worker may deserve more pay, but he is only entitled to the wage specified in his employment contract. Or a shifty businessman might deserve to be jailed for fraud, but he is entitled to go free due to a legal loophole.
Now, to say that "X deserves A" is not necessarily to say that "X ought to get A", for although desert provides a reason in favour of it, this need not be a conclusive reason. To take Kleinig's example, if punishing a convicted spy would likely trigger a nuclear war, then we presumably ought not to punish him, even though he deserves it.
Also, desert is always grounded on some basis, i.e. it takes the general form "X deserves A in virtue of B". It seems plausible that this basis is always backwards-looking, e.g. some past action that X performed. David Miller argues that "The range of possible desert bases coincides with the range of possible bases for appraising attitudes", i.e. those attitudes which must be directed at some particular object of evaluation (e.g. gratitude, resentment, etc., in contrast to joy or anxiety). So he argues that need is not a proper desert-basis, for it makes no sense to admire, resent, or otherwise "appraise" a person on the basis of their needs. That's not to say that need is irrelevant to justice. Rather, it is an element of justice that is distinct from desert (properly understood).
This is further supported by noting the redundancy of ascribing need as a desert basis. Usually when we say that X deserves A, this provides a new reason to give A to X. But need seems a reason all on its own - it is enough to say "X needs A" - to add that "X deserves A on the basis of this need" doesn't seem to add anything of substance. The word 'deserves' is here being used in a thin/formal sense (meaning something generic like 'X should get A') rather than substantive sense we're interested in.
Despite the backward-looking nature of desert, we might try to derive it from an indirect utilitarian foundation. That is, we recognize that certain forms of action will generally tend to promote utility, and so seek to encourage them by means of the notion of 'desert'. On this account, an action type deserves to be responded to in that manner which would tend to promote utility (if actions of that type are uniformly responded to in this way). So crimes deserve to be punished, and productive effort deserves reward.
Our institutions thus ideally ought to track desert, since we want those institutions or rules that will tend to promote utility when consistently applied. But this is easier said than done, and the practical difficulties will often mean that people's entitlements fail to match their deserts (as with the fraudster's legal loophole in the introductory example).
An interesting consequence of this view is that desert is sort of "stuck in the middle" between the foundational value of utility, and its practical realization in institutional entitlements. This makes it difficult to justify giving desert much weight when it conflicts with the other two values. Imagine a situation where all three conflict: that is, our institutional rules entitle X to A, his past actions mean that he really deserves B instead, but in utilitarian terms giving him C would have the best consequences. Should X be given A, B, or C? It seems difficult to answer B.
After all, in indirect utilitarian terms, we ought to apply our institutional rules consistently. They're the best rules we've got, and if we break them whenever we believe it beneficial to do so, there will be bad consequences. If you argue that in this particular case the entitlements are misguided, so it's better to disregard them anyway, then we also ought to disregard the equally misguided desert judgment and go straight to maximizing utility with C. On the other hand, if you recognize the danger of naive utilitarian decision-making, so reject C in favour of our more generally reliable desert-judgments, you should presumably go all the way and accept the institutional requirements of entitlement, thus going with A rather than B. Either way, stopping at the "intermediate stage" of desert seems somewhat arbitrary and inconsistent. I just thought that was a quite interesting result.