The enhanced distributed channel access (EDCA) mechanism of the IEEE 802.11e standard provides quality-of-service (QoS) support through service differentiation by using different medium-access-control (MAC) parameters for different stations. The configuration of these parameters, however, is still an open research challenge, as the standard provides only a set of fixed recommended values that do not take into account the current wireless local area network (WLAN) conditions and, therefore, lead to suboptimal performance. In this paper, we propose a novel algorithm for EDCA that, given the throughput and delay requirements of the stations that are present in the WLAN, computes the optimal configuration of the EDCA parameters. We first present a throughput and delay analysis that provides the mathematical foundation upon which our algorithm is based. This analysis is validated through simulations of different traffic sources (both data and real time) and EDCA configurations. We then propose a mechanism to derive the optimal configuration of the EDCA parameters, given a set of performance criteria for throughput and delay. We assess the effectiveness of the configuration provided by our algorithm by comparing it against 1) the recommended values by the standard, 2) the results from an exhaustive search over the parameter space, and 3) previous configuration proposals, which are both standard and nonstandard compliant. Results show that our configuration outperforms all other approaches.