At the beginning of 1679 Pepys was elected MP for Harwich in Charles II's third parliament which formed part of the Cavalier Parliament. He was elected along with Sir Anthony Deane, a Harwich alderman and leading naval architect, to whom Pepys had been patron since 1662. By May of that year, they were under attack from their political enemies. Pepys resigned as Secretary of the Admiralty. They were imprisoned in the Tower of London on suspicion of treasonable correspondence with France, specifically leaking naval intelligence. The charges are believed to have been fabricated under the direction of Anthony Ashley-Cooper, 1st Earl of Shaftesbury. Pepys was accused, among other things, of being a secret member of the Catholic Church in England. Pepys and Deane were released in July, but proceedings against them were not dropped until June 1680.