ISLAMABAD—After winning elections by a landslide last year, Pakistani Prime Minister Nawaz Sharif quickly moved to emulate another budding Muslim democracy, Turkey, in neutering the army's political might.

Now Mr. Sharif is finding out the hard way that the success of Turkish leader Recep Tayyip Erdogan in defanging the generals is more of a rare exception than a workable model to follow. His predicament shows just how hard it is for elected politicians to challenge the "deep state" of the military and security establishment...