The primary objective of the paper is to explore using reinsurance as a risk management tool for an insurance company. We consider an insurance company whose surplus can be modeled by a Brownian motion with drift and that the surplus can be invested in a risky or riskless asset. Under the above Black-Scholes type framework and using the objective of minimizing the ruin probability of the insurer, we formally establish that the excess-of-loss reinsurance treaty is optimal among the class of plausible reinsurance treaties. We also obtain the optimal level of retention as well as provide an explicit expression of the minimal probability of ruin.