Fillets are usually the most critical regions in mechanical parts especially under fatigue loading, considering that an increase in the maximum stress level considerably shortens the fatigue life of a part. The aim of this study is to find the best shape for a fillet in a shouldered shaft or plate so that the maximum equivalent stress has the lowest possible value.Optimization is achieved using a stochastic global search algorithm called the direct search simulated annealing. The boundary is defined using spline curves passing through a number of key points. The method is also applicable to shape optimization problems in which geometric constraints are imposed and, for this reason, tangential stress is not uniform along the optimal fillet boundary. Optimal shapes are obtained for flat and round bars subject to axial, bending, torsional, or combined loads. The results show that stress concentration factors close to one can be achieved even for bars with significant variations in cross-section. Besides, the region occupied by the optimum fillets is much smaller in comparison to circular or elliptical ones.