A magnitude 3.8 earthquake off the coast of Maine shook parts of the Northeast on Monday morning, with residents as far away as Boston feeling the rumble, officials said.