The African Footballer of the Year, who starred in Senegal's shock 1-0 win over France in Seoul, said he is "delighted" to be joining the Reds.
The 21-year-old Lens forward will make the switch to Anfield in time for next season.
"I have signed for five years. It's definite. The next season, I'll be there," he said.
"I am delighted to be joining Liverpool. I want to become one of the best players in the world and I'm sure that at Liverpool, with a coach like Gerard Houllier, I can do that."
Liverpool spokesman Ian Cotton said: "We can confirm that African Footballer of the Year El Hadji Diouf has now signed a five-year deal with Liverpool, which is wonderful news for everyone at the club.
"The Senegal striker will join up with his new team-mates when the squad report back for pre-season training in July."
Liverpool have already agreed terms with French side Sedan to sign Diouf's Senegalese team-mate Salif Diao.