The succession laws of the Romanov dynasty (appropriately called Romanov House Law), changed several times during their 304-year (1613-1917) rule over "all the Russias." I'll just enumerate those changes quickly to give you the big picture:
I only mentioned all of this because it shows that the Romanovs (like many royal families) kind of played it fast and loose with their inheritance laws, so situations like the one which occurred between Konstantin and Nikolai were not totally unheard of.
Anyway, when Alexandr I died with no sons, primogeniture dictated that the heir presumptive Konstantin was the first in line for the throne and Nikolai was second in line. Thus, when Konstantin publicly refused the throne in 1825 (he had done so privately in 1823 in writing no less) Nikolai became the new emperor. That's the short answer.
Maybe the more interesting question is why did Konstantin refuse the throne?
The reason that he abdicated-- at least, according to him-- was because of his morganatic marriage (or, marriage between socially "unequal" peoples) to a Polish countess Joanna Grudzińska in 1820, a station far below that of heir presumptive to one of the most ostentatious monarchies in the world. Konstantin was a man of war who reveled in his uncouth lifestyle and the position of monarch would require a severe tempering of his behavior-- a sentiment he expressed several times. The number of people who were aware of this secret abdication is a matter of historical debate. It used to be generally agreed upon that only three or four individuals (including the recently deceased Alexandr I) knew of the abdication but sources have appeared indicating that several additional members likely knew as well. Further, Alexandr I included the abdication in his manifesto (similar to a will) in 1823 which ought to have been read upon his death, but was not.
That brings up the question, "why?" once again. As the Decemberist Revolt, which occurred immediately upon Nikolai I's assumption of the throne, proclaimed their loyalty to Konstantin Pavlovich-- it's safe to say that there were those in the halls of Russian power who wished to see that the man they perceived more suited to power, indeed came to power. The Decemberists (which was a name applied to them based on the month of their revolt, not one they chose) also favored implementing the so-called Decemberist Constitution-- which extended a number of civil rights to the people that were utterly non-existent in Russia at the time (Russia had no Constitution until 1906).
Despite this attested and documented "secret abdication," Konstantin Pavlovich was announced as the successor to Alexandr I in 1825. At the time he was in Warsaw where he was ruling as the Governor of the Kingdom of Poland. Upon hearing news of his unwanted succession from Alexandr's former aid Nikolai Novosiltsev and being asked, "what is the first command of your royal highness?" Konstantin is purported to have replied, "I ask that you not refer to me by that applied [in this case meaning forced] title." (See pp. 164 of this 19th century eponymously titled biography of him-- written in pre-standardized Russian, sorry) This further demonstrates that Konstantin Pavlovich himself chose not to rule and not that he was the victim of some kind of court intrigue or machinations by his younger brother Nikolai.
That same author goes on to describe Konstantin's refusal to even appear in Saint-Petersburg to officially renounce his throne (pp. 165-166) calling its unwanted passing to him an "inconvenience," which is a pretty bizarre (though, understandable) way to describe inheriting rule over 1/6 of the planet. It also underlines that Konstantin himself was the one who decided to reject the throne and was not forced to do so, as some would have you believe.
To further support the claim that Konstantin's marriage to the aforementioned Joanna Grudzińska was one of the primary reasons that he renounced the throne, one must remember that Konstantin's grandmother (Yekaterina II the Great) had arranged a marriage for him with Princess Juliane of Saxe-Coburg-Saalfeld-- the daughter of the lord of a small German ducal house. The marriage was an unmitigated disaster with Juliane (who took the baptismal name Anya Fyodorovna) beginning to request divorce almost immediately. Konstantin spoke about the marriage negatively as well saying, "I never looked [at the marriage] as a gift. We are different souls." (pp. 166 of the aforementioned biography).
Ultimately Anya Fyodorovna "feel ill" and when her mother came to visit her, the two of them absconded back to Bavaria (not really absconded, both Konstantin and Alexandr I gave their permission) and Anya (going by her German name Juliane once more) was never to return to Russia again. No divorce was ever granted officially but as we all know, long distance is the wrong distance.
Suffice to say, this entire episode left Konstantin with a distaste for the proprieties of court life further reinforcing his decision to marry for love, regardless of the class of his bride-to-be, further eschewing the expectations of a person who planned to become emperor of Russia some day.