The nail bed underneath has been bruised. It will slowly heal and the nail grow out returning back a normal colour.
Well, you could have dropped something on it and you just forgot about it or you could have a fungus, I had one of those once and my whole toe nail fell off, it was gross!
You have bruised it - if the toe is also swollen you most likely have broken it