Etymology of the "Rats!" exclamation
Solution 1:
Drat is first used in the early 19th century as shortening of od rat, which was an euphemism for God rot.
Rats seems a shortening of od rat obtained by removing od, and used as plural to make it seems the plural of rat (the rodent).
[Reference: the New Oxford American Dictionary.]
Solution 2:
Rats have a very negative image in the mind of people, and have had for long (I believe it started with 19th century’s urbanisation, and later intensified; earlier tales of rats feature them as rather nice animals living in fields).
They're typically associated with filth, bad smell, and have be blamed for transmitting diseases. This gave rise to a number of expressions, including “to smell a rat” and the associated meaning of rat (“a person regarded as despicable”). I believe this same popular perception of the animal is responsible for the interjection.