We present a new method to test the ΛCDM cosmological model and to estimate cosmological parameters based on the nonlinear relation between the ultraviolet and X-ray luminosities of quasars. We built a data set of 1138 quasars by merging several samples from the literature with X-ray measurements at 2 keV and SDSS photometry, which was used to estimate the extinction-corrected 2500 Å flux. We obtained three main results: (1) we checked the nonlinear relation between X-ray and UV luminosities in small redshift bins up to z∼6, confirming that the relation holds at all redshifts with the same slope; (2) we built a Hubble diagram for quasars up to z∼6, which is well matched to that of supernovae in the common z = 0-1.4 redshift interval and extends the test of the cosmological model up to z∼6; and (3) we showed that this nonlinear relation is a powerful tool for estimating cosmological parameters. Using the present data and assuming a ΛCDM model, we obtain ΩM = 0.22–0.08+0.10 and ΩΛ = 0.92–0.30+0.18 (Ω = 0.28 ± 0.04 and ΩΛ = 0.73 ± 0.08 from a joint quasar-SNe fit). Much more precise measurements will be achieved with future surveys. A few thousand SDSS quasars already have serendipitous X-ray observations from Chandra or XMM-Newton, and at least 100,000 quasars with UV and X-ray data will be made available by the extended ROentgen Survey with an Imaging Telescope Array all-sky survey in a few years. The Euclid, Large Synoptic Survey Telescope, and Advanced Telescope for High ENergy Astrophysics surveys will further increase the sample size to at least several hundred thousand. Our simulations show that these samples will provide tight constraints on the cosmological parameters and will allow us to test for possible deviations from the standard model with higher precision than is possible today.