If there is a system, described by an Lagrangian $\mathcal{L}$ of the form
$$\mathcal{L} = T-V = \frac{m}{2}\left(\dot{r}^2+r^2\dot{\phi}^2\right) + \frac{k}{r},\tag{1}$$
where $T$ is the kinetic energy and $V$ the potential energy, it is also possible to define the total energy $E$ of the system
$$ E = T + V =\frac{m}{2}\left(\dot{r}^2+r^2\dot{\phi}^2\right) - \frac{k}{r}.\tag{2}$$
If the angular momentum $M$ is defined by $$ M = m r^{2} \dot{\phi},\tag{3}$$ then $E$ can be written as
$$ E = \frac{m}{2}\dot{r}^2 + \underbrace{\frac{M^2}{2mr^2}-\frac{k}{r}}_{V_\textrm{eff}\left(r\right)},\tag{4}$$
where the last two terms are written as new, "effective" potential $V_\textrm{eff}\left(r\right)$.
In addition, using the definition of $M$, the Lagrangian $\mathcal{L}$ can be written as
$$ \mathcal{L} = \frac{m}{2}\dot{r}^2 + \underbrace{\frac{M^2}{2mr^2}+\frac{k}{r}}_{-V_\textrm{eff}\left(r\right)},\tag{5}$$
where the sign of $V_\textrm{eff}\left(r\right)$ has been changed, since $\mathcal{L} = T-V$. But from this argument, it appears that there are two different possible ways to construct the same effective potential. This seems to me contradictory. Where is my mistake?