We present the results of a lattice QCD calculation of the pseudoscalar meson decay constants fpi, fK, fD and fDs, performed with Nf=2 dynamical fermions. The simulation is carried out with the tree-level improved Symanzik gauge action and with the twisted mass fermionic action at maximal twist. We have considered for the final analysis three values of the lattice spacing, a~0.10 fm, 0.09 fm and 0.07 fm, with pion masses down to mpi~270 MeV. Our results for the light meson decay constants are fK=158.1(2.4) MeV and fK/fpi=1.210(18). From the latter ratio, by using the experimental determination of Gamma(K-->mu nu_mu (gamma))/ Gamma(pi--> mu nu_mu (gamma)) and the average value of |Vud| from nuclear beta decays, we obtain |Vus|=0.2222(34), in good agreement with the determination from semileptonic Kl3 decays and the unitarity constraint. For the D and Ds meson decay constants we obtain fD=197(9) MeV, fDs=244(8) MeV and fDs/fD=1.24(3). Our result for fD is in good agreement with the CLEO experimental measurement. For fDs our determination is smaller than the PDG 2008 experimental average but in agreement with a recent improved measurement by CLEO at the 1.4 sigma level.