  Let $E/\mathbf{Q}$ be an elliptic curve of conductor $N$, let $p>3$ be a
prime where $E$ has good ordinary reduction, and let $K$ be an imaginary
quadratic field satisfying the Heegner hypothesis. In 1987, Perrin-Riou
formulated an Iwasawa main conjecture for the Tate-Shafarevich group of $E$
over the anticyclotomic $\mathbf{Z}_p$-extension of $K$ in terms of Heegner
points.
  In this paper, we give a proof of Perrin-Riou's conjecture under mild
hypotheses. Our proof builds on Howard's theory of bipartite Euler systems and
Wei Zhang's work on Kolyvagin's conjecture. In the case when $p$ splits in $K$,
we also obtain a proof of the Iwasawa-Greenberg main conjecture for the
$p$-adic $L$-functions of Bertolini-Darmon-Prasanna.
