Your best hope is that he was (somewhat) smart, and didn't copy your exact identical answers. If that's the case, I'd be (as your teacher) extremely suspicious about both your exams and call you out for it. If you want to try to salvage this, my (unethical) advice would be to talk to this buddy, ask him whether he copied every answer exactly as you did, and if so, tell him that if you're caught, to tell the professor that he cheated off of you without you knowing. However, I think you're absolutely at fault in this, so take that in mind.
But anyway, everyone screws up and makes mistakes. Do you know the repercussions for this actions at your school? Do you just fail the class or could you be potentially expelled for this?