An approach is presented to structural optimization for performance-based design in earthquake engineering. The objective is the minimization of the total cost, including repairing damage produced by future earthquakes, and satisfying minimum target reliabilities in three performance levels (operational, life safety, and collapse). The different aspects of the method are considered: a nonlinear dynamic structural analysis to obtain responses for a set of earthquake records, representing these responses with neural networks, formulating limit-state functions in terms of deformations and damage, calculating achieved reliabilities to verify constraint violations, and the development of a gradient-free optimization algorithm. Two examples illustrate the methodology: 1) a reinforced concrete portal for which the design parameters are member dimensions and steel reinforcement ratios, and 2) optimization of the mass at the cap of a pile, to meet target reliabilities for two levels of cap displacement. The objective of this latter example is to illustrate model effects on optimization, using two different hysteresis approaches.