The James Madison who contributed to the Federalist Papers is famous for a system of checks and balances meant to limit the power of the majority, because the many might turn against the few and the common good. This was before the United States came into being and before Madison had experience in electoral politics and national office. By 1834, the federal system had operated for 45 years and Madison had held several offices in it, including president. After that experience, he shifted in a majoritarian direction, at least according to this unsent letter. (H/t Ian Shapiro, Politics Against Domination, p. 62).
Madison first says (we don’t know to whom),
You justly take alarm at the new doctrine that a majority Govt. is of all Govts. the most oppressive. The doctrine strikes at the root of Republicanism, and if pursued into its consequences, must terminate in absolute monarchy, with a standing military force; such alone being impartial between its subjects, and alone capable of overpowering majorities as well as minorities.
Madison reviews the arguments that majority rule will become more dangerous as a jurisdiction grows in extent and as it encompasses greater economic diversity, because then huge factions will be able to dominate small and scattered minorities. He counters that differences of interest and identify emerge at all scales, “even in corporations [that] have the greatest apparent simplicity & identity of pursuits & interests.”
Acceding to the majority is generally a better choice than trying to dominate them; and the problem is least serious at a continental scale. The states, for example, are more likely to suffer from conflicts between majorities and minorities than the federal government is, and things were worse in the states before they came under federal sovereignty:
whatever may have been the just complaints of unequal laws, and sectional partialities, under the Majority Govt. of the U. S. it may be confidently observed that the abuses have been less frequent and less palpable than those which disfigured the administrations of the State Govts. whilst all the effective powers of sovereignty were separately exercised by them …
Madison’s argument in favor of majoritarianism is not that doing what the majority wants is automatically wisest and most just, but that it beats the alternatives:
Those who denounce majority Govts altogether because they may have an interest in abusing their power, denounce at the same time all Republican Govt. and must maintain that minority Govts. would feel less of the bias of interest, or the seductions of power.
He concludes with these theses:
 no Government of human device, & human administration can be perfect;  that which is the least imperfect is therefore the best Govt.  the abuses of all other Govts. have led to the preference of Republican Govt. is the best of all governments because the least imperfect.  the vital principle of Repub: Govt. is the lex majoris partis, the will of the majority;  if the will of a majority can not be trusted where there are diversified conflicting interests, it can be trusted no where because such interests exist every where ..
Madison wouldn’t call himself a “democrat,” because for him (in this letter and elsewhere) democracy means direct rule by the citizens “assembled in mass.” But he would–and did–call himself a “republican,” and for him the “vital principle” of republicanism is majority-rule.