How to cite earlier work, discovered only at the end, that claims similar results to a recently completed project?
In mathematics (maybe in other fields too), one would put at the end of the introduction a statement like "After obtaining the results in this paper, we learned of related work by X.  In particular, X obtained ...." Here the "..." would be a description like "a stronger form of our Theorem 7" or "a weaker form of our Theorem 7" or "a result related to our Theorem 7" or whatever it was that X actually got.

In computer science (maybe in other fields too), papers often have a separate section called "Related Work", and information of this sort would naturally go into that section.