Nasdaq Inc. agreed to buy off-exchange stock-trading venue LeveL Markets to expand its role in the equity market, according to people familiar with the matter.