The short answer is: Yes these two ways are equivalent. Let's look at the reason for why that is:
Let's assume we have some Observable $A$ with a discrete spectrum and a basis of eigenvectors $| a_n \rangle$ where the eigenvector $|a_n\rangle$ has the eigenvalue $a_n$. Let's also assume that our system is described by a pure state $|\psi\rangle$. Then we can write
\begin{equation}
|\psi\rangle = \sum_{n} c_n |a_n\rangle
\end{equation}
with some coefficients $c_n$. If we choose $A$ to be the Hamiltonian of the system, then $|a_n\rangle = |n\rangle$ are the energy eigenstates. In this case the equation is the same as your first equation. Now if we measure $A$, the probability for measuring the eigenvalue $a_m$, which corresponds to the eigenstate $|a_m\rangle$, is (in the nondegenerate case)
\begin{equation}
|\langle a_m|\psi \rangle|^2 = \left| \sum_n c_n \langle a_m | a_n \rangle \right|^2 = \left| \sum_n c_n \delta_{nm} \right|^2 = |c_m|^2.
\end{equation}
If we choose the Hamiltonian as our observable $A$, this is the probability of measuring the energy corresponding to $|a_m\rangle = |m\rangle$, which you also wrote in your post.
Now let's look at the formalism employing the density matrix. For our state $|\psi\rangle$ the density matrix is $\rho = |\psi\rangle\langle\psi |$. If we measure $A$, the probability for measuring the eigenvalue $a_m$ is
\begin{equation}
\langle a_m |\rho| a_m \rangle = \langle a_m |\psi\rangle \langle \psi| a_m \rangle = |\langle a_m |\psi \rangle |^2 = |c_m|^2.
\end{equation}
In the last step I used the fact that we already calculated $|\langle a_m |\psi \rangle |^2$ earlier in this post. So as you see, we get exactly the same result as before.
One last thing: Note that the density matrix formalism is more general in the sense that not every density matrix corresponds to a pure state. Therefore the second method can always be applied but the first method can only be applied if the state is pure. However, if the state is pure, the two methods are equivalent.