Conservative leader Friedrich Merz has won a parliament vote to become Germany's next chancellor at the second attempt.