As far as I can tell, the talmud in Bava Kamma 92a is the earliest source for the statement, though its phrasing indicates the principle was known earlier:
Rava said to Rabba bar Mari: From where is this matter derived whereby the Sages stated: Anyone who asks for compassion from Heaven on behalf of another, and he requires compassion from Heaven concerning that same matter, he is answered first? Rabba bar Mari said to him that the source for this is as it is written: “And the Lord changed the fortune of Job, when he prayed for his friends” (Job 42:10).
Job 42:10 is the source cited in the g'mara there, but commentaries on the passage from Job provide further information. Pesikta Rabbati, written in the 9th century CE (i.e. much later than the g'mara), connects Job's change of fortune to his repentance for standing against his friends. It's not just that he prayed for others before himself, but that he had been feuding with them and still asked for mercy for them rather than for himself:
So long as Job stood against his friends and they against him, the attribute of justice prevailed. [...] At the very moment when he forgave them and prayed for mercy upon them, the Holy One returned to him, as it says “The LORD restored Job’s fortunes…” (Job 42:10) When? “when he prayed on behalf of his friends…” (ibid.) (Pesikta Rabbati 38)
This commentary then goes on to state the general principle:
This is as it says elsewhere, “...show you compassion, and in His compassion increase you...” (Deuteronomy 13:18). R’ Yose ben Dormaskit said: take this sign in your hand – so long as you are merciful upon your fellows, HaMakom (God) will be merciful upon you. (ibid)
It then gives another example from B'reishit, one that Rashi also gives in commenting on this g'mara:
As soon as Avraham prayed for mercy on behalf of Avimelech, he received his own reward, as it says “Abraham then prayed to God, and God healed Abimelech and his wife…” (Genesis 20:17) And what was the reward which he received? That his wife became pregnant and bore him a son, as it says “The LORD took note of Sarah as He had promised, and the LORD did for Sarah as He had spoken.” (Genesis 21:1) (ibid)
The concept that praying for others' wellbeing (even when they have wronged you) leads to God showing kindness to you too is older than Job. D'varim 13:18, cited in Pesikta Rabbati, aludes to it, though I'm having trouble seeing it as clearly as this source does. And Genesis 21 shows the principle in action, as Job does. The principle was apparently known to the authors of the g'mara, who take it as given and are just trying to source it. But, as far as I can tell, this g'mara is the oldest clear statement of the principle.