Let $X_1, \dots, X_n$ be independent identically distributed observations from an unknown probability density $f(\cdot)$. Consider the problem of estimating the level set $G = G_f(\lambda) = {x \epsilon\mathbb{R}^2: f(x) \geq \lambda}$ from the sample $X_1, \dots, X_n$, under the assumption that the boundary of G has a certain smoothness. We propose piecewise-polynomial estimators of G based on the maximization of local empirical excess masses. We show that the estimators have optimal rates of convergence in the asymptotically minimax sense within the studied classes of densities. We find also the optimal convergence rates for estimation of convex
level sets. A generalization to the N-dimensional case, where $N > 2$, is given.