All you have to do is point out that he wrote the code and back up your assertion. It's that simple. Don't make it complicated.
You write that the "code was a joint effort" and you wonder why you got nailed for the code and you're asking us how to get out from under the blame. You just muddied the waters, pal. And you screwed yourself big time when you wrote that "the code was a joint effort", meaning that you are fully blamable. Are you trying to get yourself fired for what the other guy did? Because it sure looks like it.
What you have to do is make it clear that your partner in crime wrote the code. Now. And going forward, think about the implications about what you are saying before you say it. In general, you acknowledge responsibility for your own actions. You do NOT acknowledge responsibility for somebody else's actions. Not unless you have direct authority on them.
Follow-up comment from OP Well I don't think I "screwed myself big time". No one is getting fired. The situation is mildly irritating at worst
It's good to hear that you're not getting fired. But be careful - Emails are not usually that long. And checking in defective code into repositories is not a small matter
Follow-up comment from @jammypeach I didn't downvote, but I have to point out that while the OP was blamed for the problem he was also assigned the task of fixing it. Him saying that he didn't write the problem code does not complete the assigned task nor does it come off as professional IMO. I think the answer written by Chris addresses this in a way that's less likely to cause an problem for the OP
@ChrisLively wrote "As a manager, if I haul off on a person because of something that someone else did then I would hope that the employee would politely tell me what's what. I'd then apologize and vent my ire where it belongs." If the OP does not speak for himself, he can pretty much assume that nobody will. I am pretty sure that Chris would not take it well the answer that "the code was a joint effort" and he would conclude from that answer that the OP was partially responsible for the code - I would. If the OP was specifically assigned the task of cleanup, he complies but he should not give anyone the impression that the code he is cleaning up is his. Part of being a professional is being accountable. And part of being accountable is putting the accountability where it belongs.
Follow-up comment from @ChrisLively "Your assumption about how I would take that is correct. Also I agree that the OP should point out whose code it was. WesleyLong above had perhaps the best way to phrase such an email."
For reference, the comment from @WesleyLong "Don't accept the blame. Ignore blame. It is a faulty concept from immature and defensive thinking. Report the facts: "The code in question is not mine." Accept the assignment: "I will complete THE (Editing myself) assignment by Thursday."
Personally, I already get enough justifiable blame for the things I did or din't do without having to deal with getting blamed for what somebody else did or didn't do, on whom I have no control or influence.