We give a randomized algorithmic version of the Balog--Szemer\'edi--Gowers theorem for sets of integers. Let $A\subseteq[N]$ have size $n:=|A|\geq2$, let $1\leq K\leq n$, and suppose that its additive energy satisfies $E(A)\geq n^3/K$. Reiher and Schoen proved existentially that, for every fixed $\epsilon \in (0,1/2)$, there is a subset $A'\subseteq A$ satisfying $|A'|\geq(1-\epsilon)n/\sqrt K$ and $|A'-A'|\leq O_{\epsilon}(K^4)|A'|$; the size scale $n/\sqrt K$ is essentially optimal. We give an algorithmic counterpart: with probability at least $1-n^{-10}$, our algorithm runs in time $nKN^{o(1)}$ and returns a subset $A'\subseteq A$ satisfying $|A'|\geq cn/\sqrt K$ and $|A'-A'|\leq CK^4|A'|$, where $c,C>0$ are absolute constants. Thus the output attains the essentially optimal subset-size scale and the best-known $K^4$ dependence for the normalized difference set.