Let's assume I received a letter today that accuses me of downloading an illegal file, posting something inappropriate in a forum, or hacking into a system. And that happened a few months ago. But I was running a Tor relay on the IP address stated in the letter back then. How can I prove that?
You can use ExoneraTor, a tool by Tor Project designed for that work.
Of course you should also contact a lawyer with some affinity on Internet laws so as to handle better your case. If you're located in USA you could contact EFF, a non-profit which actively and legally supports digital rights. If you're in Europe, people of Torservers could give you some advice although they're not lawyers.