STOCKHOLM, Sweden—Stefan Lofven, Sweden’s Social Democratic prime minister since 2014, said Sunday that he will step down as head of government and the party in November. The unexpected announcement—made during his annual summer speech—came ahead of next year’s general election and after Lofven in June became the first Swedish leader ever to lose a motion…