With the score tied at 3 in the eighth, Juan Uribe's bases-loaded, two-out, two-run double gave the Giants a short-lived lead. Uggla's three-run homer in the bottom of the inning put the Marlins up, 6-5.
The Giants tied it again with two out in the ninth on Aaron Rowand's solo home run. Rowand, who had three RBIs on the night, took a 1-0 slider from Marlins closer Leo Nunez and deposited it into the left-field seats.
"It was definitely [a good feeling], especially when you win the game," Rowand said. "Doesn't mean a lot if you lose."
Closer Brian Wilson, in his first game back from a tight groin, pitched a perfect 1 1/3 innings. As a whole, the Giants pitching staff totaled 20 strikeouts -- tied for second-most in franchise history, the last being on June 16, 2001, at San Diego.
And when the dust settled in the 12th inning, Tim Lincecum once again had no decision.
Through five innings, Lincecum looked like a reigning two-time Cy Young Award winner, with two hits allowed, 11 strikeouts and no walks.
But things unraveled for the right-hander in the sixth.
In a clash of two of the best players in the game today, Ramirez took Lincecum's first offering -- a badly located slider -- and deposited it into the left-field seats for a one-out, three-run homer to tie the game in the bottom of the sixth.
It took Lincecum less than five minutes to strike out Ramirez, Jorge Cantu and Uggla in order in the fourth inning. Lincecum also struck out five of the first six batters he faced.
But manager Bruce Bochy stayed with his ace in the seventh, and Lincecum retired three of the four batters he faced. His final line: seven innings, five hits, three runs, one walk and 13 strikeouts. He was in line for the win before Uggla's two-out smash off reliever Sergio Romo.
"The starter's job isn't to go out and get a win, it's to put the team in a position to get a win," said Lincecum, who acknowledged he made the one mistake to Ramirez. "I threw my seven innings, and we nitpicked and scored some big runs when we needed to and it turned into a really exciting game."
For the Giants, who averaged 3.9 runs per game on their recent 6-3 homestand, Tuesday was a bit of a coming-out party.
"We feel like we're a good offensive club and we showed it tonight," Bochy said.