Common failure on E46. That wire is the tail light ground. Cut the wire and discard the burned terminal.
Crimp new wire about 2'' to the wire you just cut. Get a spade terminal and crimp it to the new wire.
If you look closely at the tail light board you will see a spot near the bottom where the spade terminal can connect to.
Plug the connector back in and you should be good to go.