We study the continuous-time portfolio optimization problem of an insurer. The wealth of the insurer is given by a classical risk process plus gains from trading in a risky asset, modelled by a geometric Brownian motion. The insurer is not only interested in maximizing the expected utility of wealth but is also concerned about the ruin probability. We thus investigate the problem of optimizing the expected utility for a bounded ruin probability. The corresponding optimal strategy in various special classes of possible investment strategies will be calculated. For means of comparison we also calculate the related mean-variance optimal strategies.