Ryan Braun hit a three-run homer to give Milwaukee a 4-3 lead in the sixth before Sheffield tied it the next inning off Mitch Stetter, who was facing his first batter in relief of starter Dave Bush.
Sheffield, a nine-time All-Star, was on as a pinch hitter and sent a full-count pitch an estimated 385 feet for his first hit of the season.
"Now that I'm in the club it's like getting your degree. Nobody can take that away from you," Sheffield said.
After squandering a bases-loaded opportunity in the eighth, Carlos Delgado doubled off Seth McClung (0-1) to start the ninth. Delgado scored on Castillo's single to short, when a diving J.J. Hardy couldn't deliver the throw to first in time to get Castillo.
Castillo was mobbed by his teammates after he touched first base.
New York's revamped bullpen gave up just one hit over the final four innings, with J.J. Putz (1-0) pitching a perfect ninth for his first win with the Mets.
At 40 years, 143 days, Sheffield became the fourth-oldest player to hit 500 home runs behind Willie McCovey (40 years, 171 days), Eddie Murray (40, 194) and Ted Williams (41, 291).
Sheffield pumped both arms in the air as he began to round the bases, with cameras flashing throughout Citi Field. He touched home plate and pointed to the sky with both arms before hugging on-deck batter Jose Reyes.
He then received congratulatory hugs and high-fives from his new teammates, who came out of the dugout as fans gave Sheffield a prolonged ovation. He raced up the dugout steps for a curtain call, waving his helmet to the crowd of 36,436.
"That was just a great reception," Sheffield said. "I was so numb at that time."
The homer, the second as a pinch-hitter, tied the score at 4-all. It was caught by Chris Matcovich, a 22-year-old Mets fan from Suffern, N.Y., wearing a Keith Hernandez jersey.
Known as much for his outspoken personality as he is for a vicious swing that made him one of the most feared hitters in the game, Sheffield joined Hank Aaron, Willie Mays, Barry Bonds, Frank Robinson and Reggie Jackson as the only players with 500 homers and at least 2,500 hits, 1,500 RBIs and 200 stolen bases.