Let A ∈ R n×n be a symmetric random matrix with independent and identically distributed Gaussian entries above the diagonal. We consider the problem of maximizing σ, Aσ over binary vectors σ ∈ {+1, −1} n . In the language of statistical physics, this amounts to finding the ground state of the Sherrington-Kirkpatrick model of spin glasses. The asymptotic value of this optimization problem was characterized by Parisi via a celebrated variational principle, subsequently proved by Talagrand. We give an algorithm that, for any ε > 0, outputs σ * ∈ {−1, +1} n such that σ * , Aσ * is at least (1 − ε) of the optimum value, with probability converging to one as n → ∞. The algorithm's time complexity is C(ε) n 2 . It is a message-passing algorithm, but the specific structure of its update rules is new.As a side result, we prove that, at (low) non-zero temperature, the algorithm constructs approximate solutions of the Thouless-Anderson-Palmer equations.