Marc Marquez won in the wet by 9.8s at the German GP after timing his tyre swap to perfection, ahead of Cal Crutchlow and Andrea Dovizioso.