The Boston and Maine Railroad was chartered in New Hampshire on June 27, 1835, and the Maine, New Hampshire and Massachusetts Railroad was incorporated March 12, 1839, in Maine, both companies continuing the proposed line to South Berwick, Maine. The railroad opened in 1840 to Exeter, New Hampshire, and on January 1, 1842, the two companies merged with the Boston and Portland to form a new Boston and Maine Railroad.
On February 23, 1843, the B&M opened to Agamenticus, on the line of the Portland, Saco and Portsmouth Railroad in South Berwick. On January 28 of that year, the B&M and Eastern Railroad came to an agreement to both lease the PS&P as a joint line to Portland.
The Boston and Maine Railroad Extension was incorporated on March 16, 1844, due to a dispute with the Boston and Lowell Railroad over trackage rights rates between Wilmington and Boston. That company was merged into the main B&M on March 19, 1845, and opened on July 1, leading to the abandonment of the old connection to the B&L (later reused by the B&L for its Wildcat Branch). In 1848, another original section was abandoned, as a new alignment was built from Wilmington north to North Andover, Massachusetts in order to better serve Lawrence, Massachusetts.
A new alignment to Portland opened in 1873, splitting from the old route at South Berwick, Maine. The old route was later abandoned. This completed the B&M "main line", which would become known as the Western Route to distinguish it from the Eastern Route (described below), which also connected Boston and Portland.
At one point, the B&M also owned a majority of stock of the Maine Central Railroad, stretching from Quebec via northern New Hampshire to southern and eastern Maine.
Beginning in the 1930s, freight business was hurt by the leveling-off of New England manufacturing growth and by new competition from trucking. In 1925, B&M reported 2956 million net ton-miles of revenue freight and 740 million passenger-miles; at the end of the year it operated 2291 route-miles, including "42.85 miles of electric street railway". (Those totals do not include B&C, M&WR, StJ&LC or YH&B.)
The B&M's most traveled and well known passenger trains included the Alouette, Ambassador, Cheshire, Day White Mountains, East Wind, Green Mountain Flyer, Gull, Kennebec, Minute Man, Montrealer/Washingtonian, Mountaineer, Pine Tree, Red Wing, and State of Maine. However, the popularization of the automobile doomed B&M as a passenger carrier.
Discontinuances in the 1920s and 1930s primarily affected minor branches and rural intercity routes, but the 1950s saw the loss of more significant intercity routes. September, 1952 saw the first cut to the four main intercity mainlines, as Eastern Route service was cut from Portland, Maine to Portsmouth, New Hampshire. (Portland continued to see service to Boston on the Western Route through Dover, New Hampshire.) The New York-Montreal Green Mountain Flyer/Mount Royal, which had Boston sections running on the B&M via Bellows Falls, ended when the Rutland Railroad discontinued all passenger service, in 1953. The northern section of the Boston-Wells River, Vermont route ended in 1954 (thus ending connections to Quebec City), as did Manchester-Portsmouth service. Concord-Claremont Junction service ended in 1955, and the Boston section of the Ambassador was reduced to a Boston-White River Junction RDC connecting train in 1956. Fitchburg mainline service was trimmed from Troy, New York, to Williamstown, Massachusetts, in January 1958, and discontinued soon afterward.
The B&M became unprofitable in 1958 and moved to shed its money-losing passenger operations. On May 18, 1958, the B&M severely reduced Boston commuter service. The Maynard Branch, Saugus Branch, Essex Branch, and Stoneham Branch were cut, and the Central Mass Branch was cut from Clinton to Hudson. Almost all inner-suburb commuter stations within the MTA transit district were closed. Intercity service to Bellows Falls, Vermont and Brattleboro, Vermont (the Cheshire) via the Cheshire Branch was also cut. Service was trimmed again from Williamstown to Greenfield on December 30, 1958, and cut to Fitchburg on April 23, 1960. Further cuts on June 14, 1959, terminated the Swampscott Branch, Marblehead Branch, Danvers Branch, and the north half of the Woburn Loop. The State of Maine Express - the last through service between New York City and Maine - and the Boston-Halifax Gull were discontinued in 1960. Long rural lines to North Conway and Berlin, New Hampshire were cut on December 3, 1961, By 1962, the B&M was preparing ICC applications to discontinue all remaining service.
After the major cuts by the B&M and the New Haven Railroad in the late 1950s, public opinion in Massachusetts began to favor supporting Boston commuter service to prevent it from being cut entirely. From January, 1963 to March, 1964, the state Mass Transportation Commission funded an experiment testing various fares and service levels on the two railroads. On August 3, 1964, the Massachusetts Bay Transportation Authority (MBTA) was formed (as an expansion of the MTA funding district) to subsidize suburban commuter rail operations. In December, 1964, the MBTA and B&M reached an agreement for the MBTA to subsidize in-district service (within about 20 miles (32 km) of Boston) should the ICC applications be approved. Municipalities outside the MBTA district could directly subsidize continued service.
After approval of the applications, the B&M discontinued most interstate service on January 4, 1965. Service via Concord to Laconia, New Hampshire and to Montreal via White River Junction ended, though a single Boston-Concord round trip remained. Western Route service to Portland and Eastern Route service to Portsmouth were discontinued; single Boston–Dover and Boston-Newburyport round trips were retained. On January 18, 1965, commuter service was cut to the MBTA district and subsidies began. Fitchburg Route service was cut to West Concord; New Hampshire Route and Western Route service to Wilmington, save for the Concord and Dover trip; Eastern Route service to Manchester and Wenham except for the Newburyport trip; and Central Mass service to South Sudbury. After out-of-district communities agreed to subsidies, service was re-extended to Ayer, Lowell, Ipswich, and Rockport on June 28.
The Montrealer was discontinued in September, 1966; local service on the Connecticut River Line lasted until the end of that year. On June 30, 1967, the Concord trip was cut to Lowell, and the Dover trip to Haverhill. The four routes with single daily round-trips slowly ended: South Sudbury on November 26, 1971; Newburyport in April 1976; Haverhill in June 1976; and Bedford on January 10, 1977. (However, Haverhill service was restored by MVRTA subsidy in 1979.) On December 27, 1976, the MBTA bought all B&M commuter equipment, as well as most of the B&M's trackage on Boston's northside (including several abandoned lines). On March 12, 1977, the B&M also won the contract for the southside commuter rail lines that had once been part of the New Haven and B&A: the first time that Boston's commuter rail system had been operated by a single entity. The B&M operated the whole MBTA Commuter Rail system under contract to the MBTA until 1987. The final B&M line to lose passenger service was the Woburn Branch (former Woburn Loop), which was cut on January 30, 1981, due to poor track quality. Under public control, commuter rail service has returned to several lines cut by the B&M, and Portland intercity service returned with the Amtrak Downeaster, in 2001.
For much of the 1970s, the Boston and Maine limped along. In 1973 and 1974 the B&M was on the brink of liquidation. The B&M was offered the opportunity to merge its properties into the new Conrail in 1976, but opted out.
By 1980, though still a sick company, the B&M started turning-around thanks to aggressive marketing and its purchase of a cluster of branch lines in Connecticut. The addition of coal traffic and piggyback service also helped. In 1983, the B&M emerged from bankruptcy when it was purchased by Timothy Mellon's Guilford Transportation Industries for $24 million. This was the beginning of the end of the Boston & Maine corporate image, and the start of major changes, such as new labor issues which caused the strikes of 1986 and 1987, and drastic cost-cutting such as the 1990 closure of B&M's Mechanicville, New York, site: the largest rail yard and shop facilities on the B&M system.
Pan Am entered a joint venture with Norfolk Southern Railway (NS) in April, 2009 to form Pan Am Southern (PAS). PAR transferred to the PAS assets that included its 155-mile (249 km) main line track between Mechanicville, New York, and Ayer, Massachusetts, including the Hoosac Tunnel and Fitchburg line as far as Littleton, Massachusetts, and 281 miles (452 km) of secondary and branch lines, plus trackage rights, in Connecticut, Massachusetts, New Hampshire, New York and Vermont. NS transferred cash and other property valued at $140 million to the joint venture, $87.5 million of which was expected to be invested within a three-year period in capital improvements on the Patriot Corridor, such as terminal expansions, track and signal upgrades. Springfield Terminal provides all railroad services for the joint venture.