(CNN) -- In the end, it was security camera video that made the difference.
Yanira Maldonado, an Arizona mother of three children and four stepchildren who spent nine days detained in Mexico under suspicion of smuggling marijuana, was released from a Nogales, Mexico, prison Friday, mainly because of that video.
The judge's ruling, obtained exclusively by CNN, shows the surveillance video from a bus terminal and the testimony of three witnesses, were more than sufficient to convince Maria del Carmen Salcedo Garcia, a Mexican federal judge in the border city of Nogales, Mexico; to give Maldonado her freedom back.
The prosecution's case, the 29-page document shows, was merely circumstantial. In other words, Maldonado was arrested simply because one of two packages of marijuana discovered on the bus was found under her seat.
In the ruling, Salcedo Garcia calls the prosecution's case "not apt or sufficient to corroborate that Yanira Maldonado ... is the person who transported the narcotics."
Maldonado, 42, and her husband Gary, 41, were traveling together after attending her aunt's funeral in the Mexican state of Sinaloa, according to the ruling and to interviews conducted with the couple by CNN.
They boarded a bus belonging to the Tufesa bus company in the city of Los Mochis on their way back home to the town of Goodyear, outside Phoenix. Their bus was stopped at a military checkpoint May 22 in the town of Querobabi, in the state of Sonora, where three soldiers found two packages containing marijuana, the document says.
The drugs, wrapped in clear plastic with "cinnamon-colored" tape, weighed 6.003 kilos (13.23 pounds), according to evidence presented in court and referenced in the judge's ruling. It had been originally reported by Mexican authorities the two packages had a combined weight of 5.7 kilograms.
Both Yanira and Gary Maldonado were initially detained. Gary Maldonado was later released because neither of the two packages of marijuana was found under his seat. One was found under his wife's seat, number 39. The other was under seat 42, which was unoccupied.
The bus driver, identified by the court document as Jorge Luis Flores Grijalva, also was detained. He, too, was released from prison last Friday, just hours before Maldonado.
According to the judge's ruling, three witnesses -- the bus driver and two fellow passengers -- testified that the Maldonados boarded the bus in Los Mochis carrying only two blankets and her personal purse.
The surveillance video, shown to the court last Thursday at a hearing to which CNN had access, shows, in addition to the blankets and the purse, Yanira Maldonado was carrying two bottles of water and nothing more.
In issuing the ruling, Salcedo Garcia said the fact that "the narcotics in question were found under seat number 39 of bus 323 of the Tufesa Bus Company which was occupied by the defendant does not lead us to conclude in an indisputable way that the drugs were in possession of Yanira Maldonado."
The judge also sided with defense attorney Francisco Benitez in saying that it would have been impossible for the Maldonados to somehow hide such an amount of drugs while boarding.
"It is illogical and also not credible to believe the packages could've been placed (by the Maldonados) where they were found," the judge said, "without any other passenger on the bus noticing it."
Speaking to CNN last Wednesday, in her first interview from inside the prison, recorded two days before her release, Maldonado had raised the same objections the judge mentions in her ruling.
"They have cameras in the terminals, on the bus. And they haven't checked that," Maldonado told CNN. "Why don't they check for fingerprints? I don't have my fingerprints on the package."
A top official in the Mexican state of Sonora said that, so far as the Mexican government is concerned, "the case is closed." The official, speaking on condition of anonymity because he's not authorized to speak publicly about the case, said nobody else is expected to be prosecuted.
The soldiers who detained the Maldonados "were only doing their job," the official said.