No, I don't think your assumption is correct.
You didn't just remove "the middle part", you removed the subject and predicate of an independent clause, thus changing the entire grammatical structure of the sentence.
The moonlight barely made its way through,
is the first clause, and it can stand on its own. The 'and' introduces another part, which begins with a {conditional} clause with 'it' standing for "moonlight" and 'did' as the predicate.
and when it did,
Following the comma is the third clause, with its own subject ("it") and its own predicate ("was"):
it was only as a faint silver beam.
The part of that clause starting with the word "only" is the prepositional phrase ("as a ...") wrapped in an adverb phrase ("only ..."). The adverb modifies "was".
I am not sure what grammatical rule you're overlooking. Without the 'as' preposition the meaning slightly changes. The comparison with "a faint silver beam" (
a simile) becomes
a metaphor, I suppose.