Let Ω be an m-hyperconvex domain of C n and β be the standard Kähler form in C n . We introduce finite energy classes of m-subharmonic functions of Cegrell type, E p m (Ω), p > 0 and F m (Ω). Using a variational method we show that the degenerate complex Hessian equation (dd c ϕ) m ∧ β n−m = μ has a unique solution in E 1 m (Ω) if and only if every function in E 1 m (Ω) is integrable with respect to μ. If μ has finite total mass and does not charge m-polar sets, then the equation has a unique solution in F m (Ω).