We present the stellar mass-metallicity relation for 34 0.4<z<1 galaxies selected from CFRS and Marano fields, and compare it to those derived from three local samples of galaxies (NFGS, KISS and SDSS). Our metal abundance estimates account for extinction effects, as estimated from IR/optical ratios and Balmer line ratios. All three comparisons show that the intermediate mass galaxies at z~0.65 are more metal-deficient by 0.3 dex at a given M_K or stellar mass relative to z=0. We find no evidence that this discrepancy could be related to different methods used to derive mass and metallicity. Assuming a closed box model predicts a gas fraction converted into stars of 20-25% since z~0.65, if the gas fraction is 10-20% in present-day galaxies with intermediate masses. This result is in excellent agreement with previous findings that most of the decline of the cosmic star formation density is related to the population of intermediate mass galaxies, which is composed of 75% spirals today. We find no evidence for a change of the slope of the M_{star}-Z relation from z~0.65 to z=0 within the intermediate mass range (10.5<log(M_{star}) < 11.5).