Welcome to Physics StackExchange! The formal proof of the equivalence between these two formulae can be given in terms of the chain rule of derivatives, and some vector relations.
Firstly, the full version of your second equation, including the sign, and allowing an infinitesimal rotation
by an angle $d\theta$ about any arbitrary axis $\hat{n}$ (a unit vector), is
$$
\hat{n}\cdot\vec{\tau} = -\frac{d U}{d\theta}
$$
If you like, you can take this as the definition of the torque.
Applying the chain rule allows us to relate this to the force,
and to the angular derivative of the position vector $\vec{r}$:
$$
\hat{n}\cdot\vec{\tau} = -\frac{d U}{d\vec{r}} \cdot \frac{d\vec{r}}{d \theta}
= -\vec{\nabla}U \cdot \frac{d\vec{r}}{d \theta}
= -\frac{d\vec{r}}{d \theta} \cdot\vec{\nabla}U
= \frac{d\vec{r}}{d \theta} \cdot \vec{F}
$$
The general formula for actively rotating a vector by an angle $\theta$ according to the right-hand rule about an axis $\hat{n}$ is
$$
\vec{r}' = \vec{r} \cos\theta + \hat{n}\,(\hat{n}\cdot\vec{r})\,[1-\cos\theta]
+ (\hat{n}\times\vec{r}) \sin\theta
$$
but in the limit of infinitesimal rotations $\theta\rightarrow d\theta$,
$\cos d\theta\rightarrow 1$, $\sin d\theta\rightarrow d\theta$,
this reduces to
$$
\vec{r}' - \vec{r} = d\vec{r} = (\hat{n}\times\vec{r})\, d\theta
\quad \text{or} \quad \frac{d\vec{r}}{d \theta} = \hat{n}\times\vec{r}
$$
[This formula is also familiar as $(d\vec{r}/d t) = \vec{\omega}\times\vec{r}$ where the angular velocity is
$\vec{\omega}=\hat{n}\,(d \theta/dt)$].
So we end up with a scalar triple product on the right, which can be rearranged:
$$
\hat{n}\cdot\vec{\tau} = \hat{n}\times\vec{r} \cdot \vec{F}
= \hat{n}\cdot\vec{r} \times \vec{F}
$$
We can choose $\hat{n}$ to be the $x$, $y$, and $z$ axes in turn,
to give each component of
your first equation $$\vec{\tau}=\vec{r} \times \vec{F}.$$