Search engines are pledging to make it hard for UK internet users to find pirated films and music and illegally streamed sport.

Google and Microsoft's Bing have signed up to a voluntary code of practice and will ensure offending websites are demoted in their search results.

The entertainment industry reached the agreement with the tech giants after talks brokered by the government.

The initiative will run in parallel with existing anti-piracy measures.

The code - said to be the first of its type in the world - is expected to be in operation by the summer.

Google has indicated that the effort would provide a way to check that its existing anti-piracy efforts were effective, rather than committing it to adding new measures.

The Intellectual Property Office led the discussions, with the assistance of the Department for Culture, Media and Sport.

Communications watchdog Ofcom supported the talks by exploring techniques that could be used to ensure internet users avoid coming across illegal content.

Security risks

Current anti-piracy measures in the UK include court ordered site blocking, efforts to reduce advertising appearing on illegal websites and the Get it Right From A Genuine Site education campaign, which encourages fans to support the creative process.

The organisers of the new agreement say in future internet users will be more likely to be taken to bona fide providers than pirate sites where their online security could be at risk.

Eddy Leviten, director general at trade body the Alliance for Intellectual Property, said: "Sometimes people will search for something and they will end up unwittingly being taken to a pirated piece of content.

"What we want to ensure is that the results at the top of the search engines are the genuine ones. It is about protecting people who use the internet, but also protecting the creators of that material too."

Stan McCoy, of the Motion Picture Association in Europe, welcomed the code of practice, saying pirated websites are currently too easy to find via search engines.

Geoff Taylor, chief executive of music industry body the BPI said: "Successful and dynamic online innovation requires an ecosystem that works for everyone, users, technology companies, and artists and creators.

"The code will not be a silver bullet fix, but it will mean that illegal sites are demoted more quickly from search results and that fans searching for music are more likely to find a fair site."

The BBC understands that although Google has signed up to the code, it believes it already has sufficient measures in place to tackle piracy and does not plan any immediate policy changes.

"Google has been an active partner for many years in the fight against piracy online," said a spokesman for the firm.

"We remain committed to tackling this issue and look forward to further partnership with rights holders."

BBC technology correspondent Rory Cellan-Jones said if the film and music industries did not feel the new code had improved the situation, they would expect the government to increase pressure on the search engines.