versagen is mostly used in cases where somebody failed.
scheitern in cases where something failed (plan or marriage) or in a meaning where somebody failed on something (plan, task etc). So if there couldn't achieved a result.
If somebody has done his work or plan but the result it is not working/looking as it was intended to, then the result is missglückt (literally from "kein Glück" - "bad luck") or misslungen.
Sein Kuchen ist missglückt/misslungen.
Der Kuchen ist ihm missglückt/misslungen.
If you then say:
Er hat versagt
It has a more negative meaning.
Meaning: He didn't done it as it was expected (you can't or wouldn't eat that cake. Or you are his teacher and he just didn't meet the expectations).
If he failed to reach the first place (because of his cake), he himself could also say i.e.:
Ich habe versagt, weil mir der Kuchen misslungen/missglückt ist.