For desulfurization and, if necessary, for denitrification of hydrocarbon
fractions the hydrocarbon mixture is brought into contact with a
non-aqueous ionic liquid of general formula Q.sup.+A.sup.-, wherein
Q.sup.+ is a ammonium, phosphonium or sulfonium cation, that contains at
least one alkylating agent of the formula RX.sup.-, making it possible to
form ionic sulfur-containing derivatives (and, if necessary,
nitrogen-containing derivatives) that have a preferred solubility in the
ionic liquid; and the ionic liquid is separated from the hydrocarbon
mixture that is low in sulfur and nitrogen by decanting.