Britain's top counter-terrorism officer has resigned after his security blunder threatened a major anti-terror operation.