Construction on the railroad began in August 1837 after state loans and a change of route were approved in April. The first stretch to be built was from East Boston to Salem (), completed August 27, 1838. An extension to Ipswich () was completed on December 18, 1839, followed by an extension to Newburyport () on August 28, 1840, and to the New Hampshire state line () on November 9, 1840. A branch line to Marblehead opened on December 10, 1839, followed by a branch line to Gloucester in 1847 and a branch line to Amesbury in 1848. In 1861, the Gloucester branch was extended to Rockport. On August 31, 1846, the Eastern leased the Essex Branch Railroad for 5 years, and in 1865 it bought the branch outright.