What if the residual amount of credit is higher than the residual value?

Hello, I have a theoretical question. What if you have concluded a loan agreement for a car and are still about 500€ open in this loan agreement, but the car is only worth 4000€? What happens in case of total damage due to an accident? Would you then stay on the 1000€ difference? Thank you!