In this paper, a new solution method, which is an improved version of bacterial foraging (BF) technique, is proposed for optimal power flow with security constraints (OPF-SC) problem. The OPF-SC is a nonlinear programming optimization problem with complex discontinuous solution space. BF is a recently developed advanced stochastic search technique owning high exploitation and local search capabilities to search the promising areas of the solution space with high resolution. Saving the advantages of BF, the exploration capability and diversity of the search process of BF are enhanced in the proposed improved version of BF (IBF) to cover different areas of the solution space avoiding being trapped in local minima. The effectiveness of the suggested solution strategy to solve the OPF-SC problem is extensively illustrated on some well-known test systems. Moreover, the proposed IBF is compared with many recently published OPF and OPF-SC solution methods.