Which is grammatically correct?
- He wrote it wrong.
- He wrote it wrongly.
Any good dictionary should tell you that wrong can function as an adverb. Your first sentence is fine.
I would accept your second sentence grudgingly, but it's definitely a second-class citizen. It smacks of hypercorrection, sounding somewhat stiff and unnatural. I think that if a native speaker was afraid that wrong was wrong, which it's not, they'd be more likely to go for a word like incorrectly, which is marked by form as an adverb with the suffix -ly. (Wrongly is also marked with -ly, of course, but I think it sounds a little silly in place of wrong.)
So they're both grammatically correct, but the second sentence is (in my opinion) unnatural and should be avoided.