The study of relativistic particle acceleration is a major topic of high-energy astrophysics. It is well known that massive black holes in active galaxies can release a substantial fraction of their accretion power into energetic particles, producing gamma-rays and relativistic jets. Galactic microquasars (hosting a compact star of 1-10 solar masses which accretes matter from a binary companion) also produce relativistic jets. However, no direct evidence of particle acceleration above GeV energies has ever been obtained in microquasar ejections, leaving open the issue of the occurrence and timing of extreme matter energization during jet formation. Here we report the detection of transient gamma-ray emission above 100 MeV from the microquasar Cygnus X-3, an exceptional X-ray binary which sporadically produces powerful radio jets. Four gamma-ray flares (each lasting 1-2 days) were detected by the AGILE satellite simultaneously with special spectral states of Cygnus X-3 during the period mid-2007/mid-2009. Our observations show that very efficient particle acceleration and gamma-ray propagation out of the inner disk of a microquasar usually occur a few days before major relativistic jet ejections. Flaring particle energies can be thousands of times larger than previously detected maximum values (with Lorentz factors of 105 and 102 for electrons and protons, respectively). We show that the transitional nature of gamma-ray flares and particle acceleration above GeV energies in Cygnus X-3 is clearly linked to special radio/X-ray states preceding strong radio flares. Thus gamma-rays provide unique insight into the nature of physical processes in microquasars.