Due to the recession that followed the War of 1812 and his resulting business failure his life was changed by 1819. He turned to politics and served as a member of the Pennsylvania House of Representatives in 1819. He married Josephine McDermott in 1820. He also served in row offices in Huntingdon County and then as a member of the Pennsylvania Senate for the 8th district from 1835 to 1838. In 1838 Porter was nominated for governor by the Jacksonian Democrats in order to mend the split between former Governor George Wolf and the Rev. Henry A. P. Muhlenberg, as well as defeat incumbent Governor Joseph Ritner's bid for a second term. By then the public had grown tired of the Anti-Masonic Party's "witch hunts," giving Porter a slim 5,500-voter margin of victory. The election result was bitterly contested by Ritner's supporters nearly to the point of violence. Known as the "Buckshot War", Governor Ritner was forced to order militia intervention in Harrisburg for the peaceful transition of government. Porter's victory was certified by the legislature only a few days before his inauguration. Upon taking office, Porter was immediately challenged with heavy state spending, coupled with a recession that began in 1837. Affable, eloquent, but succinct in expression, his statements often moralized against the improvident profusion in spending. He obtained a tax on persons in professions and the trades that was much like an income tax, and the first tax on capitalstock shares. He cut state spending and hiring, although his administration continued the work on the expansion of canals and railroads. The governor also promoted the economic benefits of connecting canals and railroads between Pittsburgh and points west to the capitals of Ohio, Indiana, and Illinois, and to the Mississippi River at St. Louis. Although the total state debt rose twenty-five percent under Porter, the state eventually had more than enough revenue to pay the interest. Porter resisted attempts of the General Assembly to encroach upon constitutional separations of the executive and judicial branches and refused to recognize some demands of the legislature. Porter easily won re-election in 1841 over John Banks, the first Whig gubernatorial candidate to run without a coalition with the Anti-Masonic Party. During his second term, the imprisonment of people for debts was abolished, but he faced difficult decisions with a rise of anti-foreign prejudice. During "Nativist riots" in Philadelphia in 1844, Porter acted firmly to suppress violence. The new state constitution no longer allowed a third term as governor and acrimony with the assembly - including attempts to impeach him - and his own party's position against protective tariffs, which Porter favored, caused the governor to retire from politics. After 1844, he resumed his private business in iron making, returning to public life only briefly in 1856 to endorse his longtime friend James Buchanan for president. Porter became involved in promoting a transcontinental railroad through Texas and adapting anthracite coal to iron making. In 1860 he was an associate in the incorporation of the New Mexican Railway Company. He built the first anthracite coal furnace for iron in south central Pennsylvania at Harrisburg. Speaking out against Southern secession from the Union, he lived long enough to see his son, Lt. Col. Horace Porter, later a general, gain honor through many Civil War battles. As the aide-de-camp for General Grant, Horace Porter was present to witness the surrender of General Lee. It is said that Horace Porter’s book on the subject was the definitive account of the events at Appomattox Court House.
Death
David R. Porter died August 6, 1867, aged 78, from a long illness contracted the previous winter after attending a night church meeting in Harrisburg. He is buried in Harrisburg Cemetery. Porter Street in Philadelphia is named in his honor. His grandson William Wagener Porter was a prominent Philadelphia attorney and legal author.