The seven-time Formula One champion said he will leave Mercedes at the end of the season to join Ferrari.