Interestingly, New Hampshire started as the most Democratic of the three upper New England states, but by the end of the 20th century, it became significantly more Republican than its neighbors.
One factor for this was the transformation of New Hampshire's economy in the late 20th century. New Hampshire had a more industrial economy centered around mill towns where manufacturing industries like textile, brickmaking, and lumber were dominant. Towns along the Merrimack river like Nashua, Manchester, Pembroke, Franklin, and Allenstown were hubs for these industries due to their location. The presence of workers in these industries created a significant support base for Democrats throughout the New Deal era. Additionally, ethnic divisions existed where predominantly French-Canadian and Irish descended workers in these towns had stronger support for the Democratic Party during that same period.
After World War II, these industries started to decline, and in the coming decades, New Hampshire ballooned in size (doubling between 1950 and 1990). Hillsborough and Rockingham counties saw the most concentrated gains, aided by the technology sector's growth that had transformed the old mill towns. New Hampshire's low tax policies also attracted more conservative transplants from Massachusetts. As such, the state's relative affluence and favorability toward limited government policies made it a perfect fit for the Republican Party of the late 20th century. Much of these gains can still be seen today in the towns along the Massachusetts border. However, the Democrats making inroads with knowledge economy workers has been one factor that has aided New Hampshire's transformation to a state that leans Democratic in the 1990s and beyond.
Vermont's political transformation during the same period was motivated both by new left-leaning arrivals (though its population gains were far smaller and slower than New Hampshire) as well as a parochial political culture that was at odds with the national GOP. Liberal Republicanism was virtually extinct by the early 90s. The nationalization of the free-market, neocon, and religious right brand of Republican politics forced the more isolationist, secular, environmentalist state (Vermont had far-reaching environmental policies even while under Republican control) into the Democratic column today.
Two fun tidbits to corroborate this excellent analysis:
In 1920, New Hampshire voted the most Democratic relative to the nation that it ever has in the current two-party system.
In 1988, New Hampshire was Bush Sr's second-strongest state, behind only Utah.