The Lagrangian for a particle of mass $m$ in a potential well $V(r)$ is given by $$ L = \frac{1}{2}m(\dot{r}^2 +r^2\dot{\theta}^2) - V(r). $$
Working though the Euler-Lagrange equation I get
$$\frac{\partial L}{\partial r}=mr\dot{\theta}^2-\frac{\mathrm{d}V(r)}{\mathrm{d}r} $$ $$\frac{\mathrm{d}}{\mathrm{d}t}\frac{\partial L}{\partial \dot{r}} = m\ddot{r} $$
so the equation of motion for the $r$ coordinate is:
$$ m\ddot{r} = mr\dot{\theta}^2-\frac{\mathrm{d}V(r)}{\mathrm{d}r}. $$
Now the above Lagrangian tells me that there is a conserved quantity $ \frac{\partial L}{\partial \theta} = mr^2\dot{\theta} = l$ so I can express the equation of motion as
$$ m\ddot{r} = \frac{l^2}{mr^3}-\frac{\mathrm{d}V(r)}{\mathrm{d}r}.\tag{1} $$
Well if I was to substitute $l$ directly into the Lagrangian before solving for the equations of motion I get
$$ L = \frac{1}{2}m\bigg(\dot{r}^2 + \frac{l^2}{m^2 r^2}\bigg) - V(r). $$
This Lagrangian gives me
$$\frac{\partial L}{\partial r} = -\frac{l^2}{mr^3} - \frac{\mathrm{d}V(r)}{\mathrm{d}r} $$
and the equation of motion
$$ m\ddot{r} = -\frac{l^2}{mr^3}-\frac{\mathrm{d}V(r)}{\mathrm{d}r}. \tag{2}$$
I have a minus sign on the first term on the RHS and I have a contradiction between $(1)$ and $(2)$. What is going on?