Melting of carbonated sediment in the presence of graphite or diamond was experimentally investigated at 7.5-12 GPa and 800-1600 degrees C in a multianvil apparatus. Two starting materials similar to GLOSS of Plank and Langmuir (Chem Geol 145: 325-394, 1998) were prepared from oxides, carbonates, hydroxides and graphite. One mixture (Na-gloss) was identical in major element composition to GLOSS, and the other was poorer in Na and richer in K (K-gloss). Both starting mixtures contained similar to 6 wt% CO2 and 7 wt% H2O and were doped at a similar to 100 ppm level with a number of trace elements, including REE, LILE and HFSE. The near-solidus mineral assemblage contained a silica polymorph (coesite or stishovite), garnet, kyanite, clino-pyroxene, carbonates (aragonite and magnesite-siderite solid solution), zircon, rutile, bearthite and hydrous phases (phengite and lawsonite at <9 GPa and the hydrous aluminosilicates topaz-OH and phase egg at >10 GPa). Hydrous phases disappear at similar to 900 degrees C, and carbonates persist up to 1000-1100 degrees C. At temperatures >1200 degrees C, the mineral assemblage consists of coesite or stishovite, kyanite and garnet. Clinopyroxene stability depends strongly on the Na content in the starting mixture; it remains in the Na-gloss composition up to 1600 degrees C at 12 GPa, but was not observed in K-gloss experiments above 1200 degrees C. The composition of melt or fluid changes gradually with increasing temperature from hydrous carbonate-rich (<10 wt% SiO2) at 800-1000 degrees C to volatile-rich silicate liquids (up to 40 wt% SiO2) at high temperatures. Trace elements were analyzed in melts and crystalline phases by LA ICP MS. The garnet-melt and clinopyroxene-melt partition coefficients are in general consistent with results from the literature for volatile-free systems and silicocarbonate melts derived by melting carbonated peridotites. Most trace elements are strongly incompatible in kyanite and silica polymorphs (D < 0.01), except for V, Cr and Ni, which are slightly compatible in kyanite (D > 1). Aragonite and Fe-Mg carbonate have very different REE partition coefficients (DMst-Sd/L similar to 0.01 and D-Arg/L similar to 1). Nb, Ta, Zr and Hf are strongly incompatible in both carbonates. The bearthite/melt partition coefficients are very high for LREE (> 10) and decrease to similar to 1 for HREE. All HFSE are strongly incompatible in bearthite. In contrast, Ta, Nb, Zr and Hf are moderately to strongly compatible in ZrSiO4 and TiO2 phases. Based on the obtained partition coefficients, the composition of a mobile phase derived by sediment melting in deep subduction zones was calculated. This phase is strongly enriched in incompatible elements and displays a pronounced negative Ta-Nb anomaly but no Zr-Hf anomaly. Although all experiments were conducted in the diamond stability field, only graphite was observed in low-temperature experiments. Spontaneous diamond nucleation and the complete transformation of graphite to diamond were observed at temperatures above 1200-1300 degrees C. We speculate that the observed character of graphite-diamond transformation is controlled by relationships between the kinetics of metastable graphite dissolution and diamond nucleation in a hydrous silicocarbonate melt that is oversaturated in C.