The New York Mets obtained first baseman Keith Hernandez, the National League batting champion in 1979, from the St. Louis Cardinals yesterday in exchange for pitchers Neil Allen and Rick Ownbey. The deal was announced shortly before the trading deadline.

Hernandez, 29, is hitting .284 with three home runs and 26 RBI.

Allen, the Mets' bullpen ace until this season, is 2-7 and has been undergoing therapy for stress. Ownbey (1-3) will report to AAA Louisville.

When the trade was announced on the scoreboard at Busch Stadium, many fans booed.

"We need pitching," Manager Whitey Herzog of the Cardinals said. He said he wants more speed in his lineup, too. Right fielder George Hendrick will move in to first base and Andy Van Slyke (.366 at Louisville) will play right field. Infielder Mike Ramsey, who is having back spasms, went on the 15-day disabled list to make room for Van Slyke.

The Mets also sent veteran first baseman/outfielder Mike Jorgensen to Atlanta for cash or a player to be named later and sent catcher Ronn Reynolds to AAA Tidewater.

There were two deals in the American League:

Oakland traded right-hander Matt Keough (2-3, 5.52 ERA) to New York for pitcher Ben Callahan (2-0 in AA Nashville) and first baseman-designated hitter Marshall Brant (.197 in AAA Columbus).

Keough, who won 16 in 1980, is to start Sunday against Milwaukee. Callahan is expected to stay with the A's, but Brant will go to AAA Tacoma.

The White Sox traded second baseman Tony Bernazard (.262) to Seattle for second baseman Julio Cruz (.254). Cruz leads the league with 33 stolen bases.