The Pirates, seeking their first post-season appearance since 1992, sent minor league first baseman Aaron Baker headed to Baltimore in a trade-deadline deal completed late Saturday.
Lee, 35, hitting .246 with 12 homers and 41 RBI in 85 games this season, came to the Orioles as a free agent in the off-season after spending seven seasons with Florida, six with the Chicago Cubs and splitting last year between the Cubs and Atlanta.
Lee is a two-time All-Star and three-time Gold Glove winner.
"We are pleased to add a quality veteran player like Derrek Lee to our ball club," Pirates General Manager Neal Huntington said. "He is an experienced, productive right-handed hitter and solid defender who should add to our team on the field and in the clubhouse."
The Pirates ended Saturday's play with a 54-51 record, 3 1/2 games behind first-place Milwaukee in the NL Central.
Trader Joe's: Car crashes into Long Island store, injuring 11
'SNL': 'Anchorman 2' cast, One Direction sing 'Afternoon Delight' [VIDEO]