Optimization of waterflooding sweep efficiency has been widely applied in reservoir engineering to improve hydrocarbon recovery while delaying water breakthrough and minimizing the bypassed oil in reservoirs. We develop a new framework to optimize flooding sweep efficiency in geologic formations with heterogeneous properties and demonstrate its application to waterflooding and geological CO2 sequestration problems. The new method focuses on equalizing and delaying (under constant total injected volume) the breakthrough time of the injected fluid at production wells. For application to CO2 sequestration where producers may not be present, we introduce the concept of pseudo production wells that have insignificant production rates (with negligible effect on the overall flow regime) for quantification of hypothetical breakthrough curves that can be used for optimization purpose. We apply the new method to waterflooding and CO2 sequestration optimization using two heterogeneous reservoir models. We show that in water flooding experiments the proposed method improves the sweep efficiency by delaying the field breakthrough and equalizing breakthrough times in all production wells. In this case, the optimization results in increased oil recovery and decreased water production. We apply a modified version of the proposed algorithm to geologic CO2 sequestration problems to maximize the storage capacity of aquifers by enhancing the residual and dissolution trapping. The results from applying the proposed approach to optimization of geologic CO2 storage problems illustrate the effectiveness of the algorithm in improving residual and solubility trapping by increasing the contact between available fresh brine and the injected CO2 plume through a more uniform distribution of CO2 in the aquifer.