Upper Jurassic phosphate stromatolites of the Almola Sierra (Southern Spain) encrust macrofossils and hardgrounds, and form oncoids included within pelagic, condensed fossiliferous limestones. Their accretion was determined by bacterially mediated precipitation of phosphate, by the trapping and binding of fine siliciclastics and pelagic biomicrite and by the encrustation of benthonic foraminifera. Phosphorous, trace elements and rare-earth elements were concentrated from degraded organic matter and seawater by stromatolite-building communities, which mediated the formation of phosphate-rich and Fe-Al-Si-rich organic gels under oxic conditions, favouring the precipitation of amorphous mineral precursors (ACP and Fe-Al-Si oxyhydroxides). The observed Ce-enrichment for some stromatolites is explained by oxidative scavenging of Ce4+ from seawater by Fe—Mn oxyhydroxides. The bacterially mediated gels were able to migrate and fill the voids of the stromatolite structure, and later changed to carbonate-fluorapatite, haematite and poorly crystalline Fe-rich clays under postoxic conditions. Phosphatization of trapped carbonate particles also occurred. The phosphate stromatolites formed on a sediment-starved pelagic swell, during periods of no carbonate sedimentation and hardground development. Stromatolite lamination provides evidence for rhythmic alternation between bacterially mediated phosphogenesis, sedimentation and erosion, suggesting episodic changes in the sedimentary environment. Although some of the parameters that controlled phosphate precipitation associated with the stromatolites (local high organic productivity, sediment starvation, moderate depth of deposition and physicochemical conditions) were similar to those found in modern and ancient phosphogenic settings, the palaeogeographical framework and the intensity of sedimentary processes were different to those of the World's major phosphorite deposits.