Matt 11:14 And if ye will receive it, this is Elias, which was for to come.(see also Mark 9:13)
John 1:21 And they asked him, What then? Art thou Elias? And he saith, I am not.
In this alleged contradiction, a false dichotomy has been set up here. Keener [Matthew commentary, 439] notes that later rabbis interpreted Malachi as saying that Elijah, who had not actually died (but was taken up in a whirlwind), would himself return. John was aware that he was the Elijah-to-come predicted in Malachi and told the Jews in John 1 something to the effect of "I am not Elijah in the sense that you think of it."
Support for this thesis comes from the fact that John presents the Jews in his gospel as being blind to the Scriptures. And with their mistaken notion of who and what the Messiah should be like, it is not unreasonable at all to think that they might be mistaken on the nature of the Elijah-to-come mentioned in Malachi. The Jews might have been thinking that this Elijah-to-come would be the "real live" Elijah of the books of the Kings physically returning from heaven, and John's denial was aimed at refuting the notion that he was the "real and live" Elijah.
It would have been interesting to hear John's response to the question "Are you here in the spirit of Elijah?" (A reader noted such a distinction in Luke 1:17: "And he will go on before the Lord, in the spirit and power of Elijah...")
A reader has also made this interesting observation, concerning these verses:
Hosea 3:5 Afterward shall the children of Israel return, and seek the LORD their God, and David their king; and shall fear the LORD and his goodness in the latter days.
Ezekiel 34:23-24 And I will set up one shepherd over them, and he shall feed them, even my servant David; he shall feed them, and he shall be their shepherd. And I the LORD will be their God, and my servant David a prince among them; I the LORD have spoken it.
In these passages the Messianic king is called "David" -- and this is the same sense in which John is properly called "Elijah" by Malachi 4.
Objection: And where in our Scriptures is it written that Elijah would be mistreated, as Jesus claimed (Mark 9:13)?
The allusion here is a midrashic one to 1 Kings 19:1-3, "And Ahab told Jezebel all that Elijah had done, and withal how he had slain all the prophets with the sword. Then Jezebel sent a messenger unto Elijah, saying, So let the gods do to me, and more also, if I make not thy life as the life of one of them by to morrow about this time. And when he saw that, he arose, and went for his life, and came to Beersheba, which belongeth to Judah, and left his servant there."
Those who doubt such an application is possible should reckon with Jewish exegetical techniques of the period as explained here.