There is some parallel to Turkey, the military there had a lot of influence, until Erdogan out maneuvered them. The military in Turkey were supposedly protecting democracy and keeping the state secular, but threatening coups against democratically elected politicians doesn't scream protecting democracy to me.
European countries had a working relationship with Erdogan in the beginning because of this. Obviously power corrupted in the end.
It feels like a similar situation with Imran Khan (both did time in prison on politically motivated charges), but I don't know enough about Pakistani politics to be sure.