Verizon Communications Inc. is nearing a deal to buy Yahoo! Inc., beating out rival bidders including Dan Gilbert, people familiar with the matter said.

Verizon is discussing a price close to $5 billion for Yahoo's core internet business, one of the people said. The deal doesn't include the company's patents at this stage, the person said. While other assets including Yahoo's real estate were also on the block, it could not immediately be learned if they are part of the deal.

The companies may be ready to announce the deal in the coming days, the people said, asking not to be named because the deliberations are private. The two companies are in one-on-one discussions, one of the people said. The deal hasn't been finalized and may still fall apart, they said.

A Verizon-Yahoo deal would mean loss for the bids by Quicken Loans founder Gilbert and AT&T Inc., as well as buyout firms Vector Capital Management and TPG which were also active in the bidding process until the end.

A representative for Verizon declined to comment. A representative for Sunnyvale, California-based Yahoo couldn't immediately be reached outside of regular business hours.

The deal would end a months-long bidding process for Yahoo, which began earlier this year when CEO Marissa Mayer — after keeping investors at bay for years — said the company would explore strategic alternatives, including selling its main internet operations.

Mayer was finally bowing to rising shareholder ire that gained steam after the collapse of a plan to spin off Yahoo's stake in Alibaba Group Holding Ltd. in a way that would minimize the tax impact for investors. Alibaba, the largest e-commerce provider in China, had emerged as the most valuable piece of Yahoo, and investors sought a way to realize some of those gains. After U.S. regulators failed to give prior approval for the transaction's tax status, Yahoo was forced to jettison the plan.