Middle to Upper Miocene sedimentary successions in the Alborz sedimentary basin (northern Iran) form the caprock of the Lower Miocene gas reservoirs. Their stratigraphic and sedimentological studies have been of interest to geological studies. Due to their importance, in this research, two suitable stratigraphic sections in the Zanjan and Hashtroud regions (northwest of Iran) have been subjected to detailed sedimentological and stratigraphic study to determine the origin and tectonic setting. Clastic-evaporite sediments of the middle to upper Miocene (Upper Red Formation) in the northwest of Iran are about 950 m thick, which is placed on the hydrocarbon reservoirs of the Qom Formation (Lower Miocene) with a discontinuous and abrupt boundary, and are covered by conglomerate and unhardened sediments belong to Pliocene. These sediments in the northwest of Iran are divided into four lithostratigraphic units, including (1) green marls with gypsum, (2) red marls along with gray and red sandstones, (3) red and green marls, and (4) green marls. Based on microscopic studies, the sandstones of this formation are composed of sedimentary and metamorphic rock fragments, quartz, and to a lesser extent, feldspar, pyrite and chlorite, in order of importance. The matrix (carbonate mud) and, to a lesser extent, calcite and evaporite cements form the groundmass of studied sandstones. Based on petrographic studies, these fine-to medium-grained sandstones are litharenite to feldspathic litharenite with an average composition of Q38F13RF49. Also, based on the main constituent components of sandstones and geochemical analysis of major and minor elements, and by drawing different types of separating diagrams, the tectonic setting of these sandstones are considered as an active continental margins and foreland basins (collision belts between Arabia-Eurasia continental plates), which originate from fine-to medium-grained siliceous-clastic rocks, metamorphic, carbonate, and intermediate to felsic igneous rocks outcropped in the region. The data show that these sediments are influenced by arid to semi-arid climate and moderate degree of chemical weathering, mainly from the outcrops of Takab Complex and Qom Formation (Lower Miocene), which have significant outcrops and, to a lesser extent, from Eocene volcanics. The research results are consistent with the paleogeography of the region and previous studies and can be of interest to sedimentologists and other researchers related to petroleum geology.