If radiation causes cancer how does it treat cancer?

If radiation causes cancer how does it treat cancer?