We present a multifrequency approach which optimizes the constraints on cosmological parameters with respect to extragalactic point source and secondary anisotropy contamination on small scales. We model with a minimal number of parameters the expected dominant contaminations in intensity, such as unresolved point sources and the thermal Sunyaev–Zel'dovich effect. The model for unresolved point sources, either Poisson distributed or clustered, uses data from Planck early results. The method presented is the first one where the models of the point-source contributions are based on the Planck early data. To reduce the number of parameters necessary to characterize the residuals, the method uses the knowledge of the frequency dependences of the residual signals coming from the data. The dependences are directly included in the parametrizations, allowing us to reduce the number of the residual parameters to the minimum of three. The overall three amplitudes of the residual contributions are included in a Markov chain Monte Carlo analysis for the estimate of cosmological parameters. We show that our method is robust: as long as the main contaminants are taken into account, the constraints on the cosmological parameters are unbiased regardless of the realistic uncertainties on the contaminants. Although general, the method is applied only to Planck.