Ionic liquids (ILs) are organic molten salts with low-temperature melting points that hold promise as next-generation environmentally friendly boundary lubricants. This work examines the relationship between tribological and rheological behavior of thin films of five imidazolium ILs using a surface force apparatus to elucidate lubrication mechanisms. When confined to films of a few nanometers, the rheological properties change drastically as a function of the number of confined ion layers; not only the viscosity increases by several orders of magnitude but ILs can also undergo a transition from Newtonian to viscoelastic fluid and to an elastic solid. This behavior can be justified by the confinement-induced formation of supramolecular clusters with long relaxation times. The quantized friction coefficient is explained from the perspective of the strain relaxation via diffusion of these supramolecular clusters, where higher friction correlates with longer relaxation times. A deviation from this behavior is observed only for 1-ethyl-3-methylimidazolium ethylsulfate ([C2C1Im][EtSO4]), characterized by strong hydrogen bonding; this is hypothesized to restrict the reorganization of the confined IL into clusters and hinder (visco)elastic behavior, which is consistent with the smallest friction coefficient measured for this IL. We also investigate the contrasting influence of traces of water on the thin-film rheology and tribology of a hydrophobic IL, 1-ethyl-3-methylimidazolium tris(pentafluoroethyl)trifluorophosphate, [C2C1Im][FAP], and a hydrophilic IL, [C2C1Im][EtSO4]. [C2C1Im][EtSO4] remains Newtonian under both dry and humid conditions and provides the best lubrication, while [C2C1Im][FAP], characterized by a prominent solid-like behavior under both conditions, is a poor lubricant. The results of this study may inspire molecular designs to enable efficient IL lubrication.