Is it legal for an agent to have the buyer's attorney instruct the seller's attorney to release earnest money to the seller early, before closing?

As a general rule, no. The deposit stays in escrow until closing, because releasing it early hands away your leverage. Your earnest money sits with the escrow holder, attorney, or title company as a neutral party precisely so neither side can grab it before the deal is done. The one exception is early release written into the original purchase contract with both parties agreeing up front. That happens, but rarely, on the order of a handful of deals out of a hundred in our experience, and we've never had a buyer client agree to hand over a deposit before closing. Once that money is released to the seller, your leverage is largely gone if something later falls apart. If an agent asks you mid-transaction to have your attorney instruct the seller's attorney to release the funds early, usually so the seller can relocate or lock up another property, slow down. That's the seller's problem to solve, and you don't need to absorb the risk. Ask why it's being requested, and have your own attorney spell out what protections you'd be giving up. If early release wasn't negotiated into the contract, you're under no obligation to agree.