In this paper, we present a simple, distributed algorithm for frequency control and optimal economic dispatch of power generators. In this algorithm each generator independently adjusts its power-frequency set-points of generators to correct for generation and load fluctuations using only the aggregate power imbalance in the network, which can be observed by each generator through local measurements of the frequency deviation on the grid. In the absence of power losses, we prove that the distributed algorithm eventually achieves optimality i.e. minimum cost power allocations, under mild assumptions (strict convexity and positivity of cost functions); we also present numerical results from simulations to compare its performance with traditional (centralized) dispatch algorithms. Furthermore, we show that the performance of the algorithm is robust in the sense that even with power losses it corrects for frequency deviations, and for low levels of losses, it still achieves near-optimal allocations; we present an approximate analysis to quantify the resulting suboptimality.