I came to realize I'm no match for him in math.

Literal

I [topic-は] math [in-で] [contrast-は] him [to-に] cannot-match [nominalizer-こと] [subject-が] well understood.

かなわない ('can't match, can't compete with') takes に for the person one can't match. では stacks で (domain) + は (contrastive) — 'as for in math.' ことがよくわかった ('thoroughly understood that...') uses the nominalizer こと to turn the clause into a noun phrase.