Let $(X,\alpha)$ be a K\"ahler manifold of dimension $n$, and let $[\omega] \in H^{1,1}(X,\mathbb{R})$. We study the problem of specifying the Lagrangian phase of $\omega$ with respect to $\alpha$, which is described by the nonlinear elliptic equation
\[
\sum_{i=1}^{n} \arctan(\la_i)= h(x)
\]
where $\la_i$ are the eigenvalues of $\omega$ with respect to $\alpha$. When $h(x)$ is a topological constant, this equation corresponds to the deformed Hermitian-Yang-Mills (dHYM) equation, and is related by Mirror Symmetry to the existence of special Lagrangian submanifolds of the mirror. We introduce a notion of subsolution for this equation, and prove a priori $C^{2,\beta}$ estimates when $|h|>(n-2)\frac{\pi}{2}$ and a subsolution exists. Using the method of continuity we show that the dHYM equation admits a smooth solution in the supercritical phase case, whenever a subsolution exists. Finally, we discover some stability-type cohomological obstructions to the existence of solutions to the dHYM equation and we conjecture that when these obstructions vanish the dHYM equation admits a solution. We confirm this conjecture for complex surfaces.