The Talmud (Rosh Hashanah 17a) teaches that when Moses begged for forgiveness after the sin of the Golden Calf, God wrapped Himself in a tallit, so to speak, and taught Moses the words that the Jewish people should use wherever they wished to pray for forgiveness in the future. These words are the 13 attributes of God's mercy (Exodus 34: 6-7).
They are the core of the Selichot prayers that are said at night in the days and weeks leading up to Rosh Hashanah. (Sephardim start from Rosh Chodesh Ellul; Ashkenazim begin on the Saturday night before Rosh Hashanah, or the Saturday night before that if Rosh Hashanah is on a Monday or Tuesday).
The first mention of a set Selichot service is in the ninth-century siddur of Rav Amram Gaon. It is said that in the shtetl the shul beadle with his oil lamp used to knock on people's doors in the dead of night to rouse them to come to Selichot. These days it is most common to say Selichot right before the Shacharit morning service, except for the first when musical Selichot are usually said after midnight.
The selichot begin the process of soul-searching and introspection that lead up to Rosh Hashanah. As one parable has it, we want to arrive at Rosh Hashanah as friends with God, not as strangers.