Baseball also will test for amphetamines for the first time starting next year under the deal, which must be ratified by owners and players.
Baseball's current steroid penalties are a 10-day suspension for a first offense, 30 days for a second offense and 60 days for a third. The earliest a player could be banned for life is a fifth offense.
"This is an important step to reaching our goal of ridding our sport of performance-enhancing substances and should restore the integrity of and public confidence in our great game," commissioner Bud Selig said in a statement. "I appreciate the effort put forward by the players' association and our players in reaching this new agreement."
The sport's second new steroids agreement in 10 months came after lengthy negotiations prompted by urging from Congress, including the threat of legislation that would require higher penalties and stricter testing standards.
"This agreement reaffirms that major league players are committed to the elimination of performance-enhancing substances and that the system of collective bargaining is responsive and effective in dealing with issues of this type," union head Donald Fehr said in a statement.
Representatives of the owners and players were on Capitol Hill on Tuesday to meet with House Government Reform Committee Chairman Tom Davis, R-Va. He's one of a handful of lawmakers who have introduced steroids bills.
It was his panel that held the March 17 hearing with Rafael Palmeiro, Mark McGwire and Jose Canseco. At that hearing, Selig and Fehr were scolded for what congressmen called a weak penalty system for drug testing.
The next month, Selig made a 50-100-lifetime proposal. In September, Fehr countered with 20 games, 75 games and, for a third offense, a penalty set by the commissioner.
There is no question that pressure from Congress helped make this deal happen, CBS News correspondent Bob Fuss reports. The players and owners were put in a position of knowing if they didn't do something voluntarily, Congress would force them.
At a Sept. 28 hearing of the Senate Commerce, Science and Transportation Committee, Sen. John McCain, R-Ariz., upbraided Fehr in particular for not having reached a deal on a new steroids policy.
"We're at the end here, and I don't want to do it, but we need an agreement soon. It's not complicated. It's not complicated. All sports fans understand it," McCain said at the hearing. "I suggest you act and act soon."
, McCain and Sen. Jim Bunning, R-Ky., revised their proposed legislation to soften the penalties from two years for a first offense and a lifetime ban for a second. The bill now calls for a half-season ban for a first positive test, one season for a second and a lifetime penalty for a third. Their bill would apply to the major leagues, the NFL, NBA, NHL and baseball's minor leagues.