Martha Coakley won Tuesday’s Democratic gubernatorial primary because she posted huge numbers in urban areas and lower-income communities. Coakley’s overall margin of victory has worried some observers, because the six-point spread between her and Steve Grossman was far narrower than it was expected to be. But a deeper dive into Tuesday’s returns show that Coakley ran strongly in the kinds of communities she will need to win in a November matchup against Charlie Baker, the Republican nominee for governor.

Coakley, the current state attorney general, outpaced Grossman, the current state treasurer, by six points overall. She collected 42 percent of the primary vote, compared to Grossman’s 36 percent, and Don Berwick’s 21 percent. The primary returns show a pronounced break along class lines. Coakley and Grossman ran a tight contest in wealthier suburban communities across Massachusetts. But Coakley notched large victories in densely populated urban communities, and her strength in urban communities paced her to victory on Tuesday.

Coakley took Boston by 14 percentage points. She won Springfield by 21, Brockton by 14, Worcester by 13, and New Bedford by 16. She overwhelmed Grossman and Berwick in Lawrence and Chelsea, posting 29-point margins in each city.

The large margins Coakley posted in these urban areas speak to a larger fault line in the Democratic primary vote.

Median household income in Massachusetts (the income earned by a typical family in the state) is roughly $66,700. A disproportionate share of lower income residents are concentrated in the state’s urban centers, while the suburbs are home to larger numbers of residents whose incomes exceed the state median.

The race between Coakley and Grossman in these better-off towns was extremely tight. In towns where the local median income exceeds the state median, Coakley outpolled Grossman by 1.5 percentage points — 39.5 percent to Grossman’s 38 percent. But she posted a margin of more than 11 percentage points — 45 percent to Grossman’s 34 percent — in communities where local median incomes are lower than the state income benchmark.

Primary Results and Demographics, by TownClick on a town on the map to highlight the data point on the chart below.

Berwick took 22 percent of the vote in wealthier communities, and 20 percent in less-wealthy cities and towns. He won a smaller group of very wealthy suburbs like Concord, Lincoln, and Carlisle, and also liberal western communities like Great Barrington and Northampton.

Coakley shouldn’t have to worry about having the wealthier suburbs Grossman and Berwick won, like Newton, Brookline, Lexington and Wayland, come home to her in November; they’ve been reliably Democratic communities for years. It’s more notable that Coakley made her strongest showings in the cities — the kinds of communities where she needs to run up the score in November.

In 2010, when Gov. Deval Patrick topped Baker by 6 points overall, he beat Baker by 20 percentage points in cities and towns that fall below the state median income. Patrick’s margins in poorer cities overwhelmed the 3-point edge Baker enjoyed in wealthier-than-average towns. If Coakley is going to win in November, she needs to follow the urban roadmap Patrick laid out four years ago. Baker’s campaign knows this. He’s made roughly a dozen campaign visits to Lowell, and has held scores of campaign events in Boston. He hosted his primary night party in Dorchester, in the same function hall Boston Mayor Marty Walsh used to celebrate his preliminary election victory last year. Tuesday’s primary results were likely closer than Coakley would have liked them to be. But the votes also show that, among the three Democratic gubernatorial hopefuls, Coakley is in the best position to follow Patrick’s lead.

This story was cross-posted to Poll Vault, a data-driven look at the 2014 election produced by WBUR, The MassINC Polling Group, and CommonWealth.