Well, that was a long one.

Astronauts Michael Massimino and Michael Good completed the eighth-longest spacewalk in history Friday afternoon, wrapping up a seven-hour, 56-minute marathon session at around 4:45 EDT.

The operation took so long because one of the three new gyroscope packages meant for the Hubble Space Telescope wouldn't fit.

After two hours of fiddling, the astronauts had to settle for a spare, refurbished unit that had been pulled off the orbiting observatory in 1999.

That means Hubble will have only four new gyroscopes -- they come in two-packs -- instead of four. But sometimes a refurbished unit is almost as good as a new one.

NASA will have to settle for that reassurance after a pair of new gyroscopes meant for the Hubble Space Telescope wouldn't fit when spacewalking astronauts tried to install them Friday.

It's "the difference between an A and an A-plus," said Hubble's deputy senior project scientist, Mal Niedner, back on the ground.

• Click here for more photos of Atlantis and its crew.

• Click here for some of Hubble's most spectacular images.

• Click here for NASA's live video feed.

• Click here to follow astronaut Mike Massimino's Twitter feed.

• Click here to visit FOXNews.com's Space Center.

"My friend Leonidas has a couple of words for you guys that are appropriate right now," shuttle commander Scott Altman told the spacewalkers with a laugh, referring to the Spartan king who died in battle in 480 B.C. "Remember this day, men, for it will be yours for all time."

"We've got a little more work to do, but thanks," replied Massimino.

Of the six gyroscopes replaced, three had failed, two were acting up and one was working properly.

Gyroscopes keep the 19-year-old Hubble telescope pointed where it should be, and hence the replacement operation was the most important part of this mission's five scheduled spacewalks.

On Thursday, another two-man team installed a powerful new camera and a computer data unit, after struggling with a stubborn bolt. NASA had hoped for an easier, less stressful spacewalk, but instead had to endure more drama.

By the time all the gyroscopes were installed, five hours of the spacewalk had passed and the spacewalkers had yet to start on the other major chore of the day.

Good drove in the bolts for the gyroscope boxes as Massimino, a returning Hubble mechanic who is over 6 feet tall, worked from inside the telescope, where he had wedged himself in head first.

"Trained my whole life for this," Massimino said.

He had a brief fright when his communication system fouled up after he first stepped out into space. For a minute or two, no one could not hear him.

"That was scary," said one of the astronauts inside when the problem cleared up. "A little bit," Massimino replied.

Space is particularly littered in this 350-mile-high orbit, and Atlantis and its crew face a greater than usual risk of being slammed by a piece of junk. As a precaution, NASA has a rescue shuttle on standby, ready to launch in just three days if necessary.

The spacewalkers also changed out some of Hubble's batteries later Friday.

Hubble's old batteries, original 20-year-old parts, had been used even longer. The hefty, nickel hydrogen batteries coming out were built before the telescope was launched in 1990.

The astronauts put in three new batteries — they come three to a pack — and the final three will go in early next week. Each pack is about the size of a big TV set.

NASA hopes to get another five to 10 years of use out of Hubble, once the Atlantis astronauts plug in all the new equipment. They also will take a crack at fixing two broken science instruments this weekend.

The mission cost NASA more than $1 billion, one-tenth of what has been spent on Hubble over the decades.

Massimino, who worked on Hubble during the last visit in 2002, is known among the Twittering crowd as Astro_Mike. He's been sending down tweets during spare moments since Monday's launch, but said before the flight that his spacewalks would be off limits for texting.

The Associated Press contributed to this report.