BEIJING — Baidu, the dominant Chinese Internet search engine, on Tuesday announced a major licensing deal with three of the world’s largest music companies that would allow Chinese Web users to legally download and stream hundreds of thousands of songs free.

The agreement between Baidu and One-Stop China, a joint venture between the Universal Music Group, the Warner Music Group and Sony BMG, will shut down access to a vast amount of pirated music and promises to broadly reshape the way China’s 450 million Web users gain access to online music. The country has long been a haven for pirated content. Baidu has been one of the chief conduits to it, much to the consternation of record labels, publishers and artists both here and abroad.

Under the two-year deal between Baidu and One-Stop China, the three music labels will license over 500,000 songs, about 10 percent of them in Mandarin and Cantonese, which will be stored on Baidu’s servers and available for free streaming and download on the site’s ad-supported MP3 search page and social music platform, Ting.

Baidu will pay a fee to the labels for each time a song is downloaded or played in a stream. It will also share revenue from online ads if that revenue exceeds a certain amount, as well as provide promotional support for the labels. The companies declined to disclose financial details of the agreement.