user137141: A transaction with a 77 bytes OP_RETURN is refused, but with shorter data (e.g. 74 bytes) is accepted, although up to 80 bytes should work.
What is the safe limit to be used?
Per these references the maximum length is 80 bytes (83 for whole script) (since v 0.11):
https://stackoverflow.com/questions/24845429/maximum-size-of-data-bitcoin-op-return-tx-can-handle
https://developer.bitcoin.org/devguide/transactions.html#null-data
The below transaction produces error: {"error":"-26: scriptpubkey"}.
Similar transactions with slightly shorter OP_RETURN are fine.
01000000000102ae5c4a7139f0f47cf4bf431d99f110e73d2cd7e03faae56d56d7c09db3ee3c400100000000fbffffffc8ab005126b7b871d7c9621789de87282f4cd13e851fd286b0e5aae02e21c0b90000000000faffffff0350c30000000000001600146f26d2633d5307d9c4b1ca5b4c282201bae4ab144e15000000000000160014bb5bb9b9a07718bd0bfeef385f6a184787b584da00000000000000004f6a4d535741503a424e422e425553443a626e62317368366e757a7474336463657679346e676d7a746b7061706e76787179376a653074307564723a3635383137323831393a74656d7963683a3330300247304402200ca03ef0f249471dbee806b0961892c7141339460a5890479fdbebd3ec06ce8d02201a2275d54849f660ba01cd2799c0ac57a4bfca6d21115ddeecf63ebfd71898df0121034df96f5dacf5e22fb8611e6863e48f6777c7e96064c81196e23dcefd35017d0e02483045022100987199ff71731d44520bc1ed3704a6a66725ea890479ea5078b6b89ebb854d8402202dd52791a28c9d28c1672785765aab811b1549a1ec031f7c15a4ee472e70c4200121034df96f5dacf5e22fb8611e6863e48f6777c7e96064c81196e23dcefd35017d0e00000000

{
    "data_hex": "535741503a ...",
    "script": "6a4d535741503a ...",
    "script_type": "null-data",
    "value": 0
}

Note: use case is client for thorswap.finance cross-chain DEX.

user137141: UPDATE: The first version of this answer suggested using two data pushes, updated to use OP_PUSHDATA1.
Further research has clarified the issue:

OP_RETURN max data length is 80 bytes, however
Maximum bytes in one push data is 75 bytes.
Therefore data of sizes between 76 to 80 need to be encoded with OP_PUSHDATA1!

The script in this transaction is in fact invalid, 6a 4d 53 57 should be interpreted as OP_RETURN OP_PUSHDATA2 53 57, after which 22355 (0x5753) bytes are expected.
Correct encoding would be to use OP_PUSHDATA1 for data of length 76 to 80 bytes.
50 6a 4c 4d <77 bytes>
OP_RETURN OP_PUSHDATA1 4d <77 bytes>

137141: <p>A transaction with a 77 bytes OP_RETURN is refused, but with shorter data (e.g. 74 bytes) is accepted, although up to 80 bytes should work.</p>
<p>What is the safe limit to be used?</p>
<p>Per these references the maximum length is 80 bytes (83 for whole script) (since v 0.11):</p>
<p><a href="https://stackoverflow.com/questions/24845429/maximum-size-of-data-bitcoin-op-return-tx-can-handle">https://stackoverflow.com/questions/24845429/maximum-size-of-data-bitcoin-op-return-tx-can-handle</a>
<a href="https://developer.bitcoin.org/devguide/transactions.html#null-data" rel="nofollow noreferrer">https://developer.bitcoin.org/devguide/transactions.html#null-data</a></p>
<p>The below transaction produces error: <code>{&quot;error&quot;:&quot;-26: scriptpubkey&quot;}</code>.
Similar transactions with slightly shorter OP_RETURN are fine.</p>
<pre><code>01000000000102ae5c4a7139f0f47cf4bf431d99f110e73d2cd7e03faae56d56d7c09db3ee3c400100000000fbffffffc8ab005126b7b871d7c9621789de87282f4cd13e851fd286b0e5aae02e21c0b90000000000faffffff0350c30000000000001600146f26d2633d5307d9c4b1ca5b4c282201bae4ab144e15000000000000160014bb5bb9b9a07718bd0bfeef385f6a184787b584da00000000000000004f6a4d535741503a424e422e425553443a626e62317368366e757a7474336463657679346e676d7a746b7061706e76787179376a653074307564723a3635383137323831393a74656d7963683a3330300247304402200ca03ef0f249471dbee806b0961892c7141339460a5890479fdbebd3ec06ce8d02201a2275d54849f660ba01cd2799c0ac57a4bfca6d21115ddeecf63ebfd71898df0121034df96f5dacf5e22fb8611e6863e48f6777c7e96064c81196e23dcefd35017d0e02483045022100987199ff71731d44520bc1ed3704a6a66725ea890479ea5078b6b89ebb854d8402202dd52791a28c9d28c1672785765aab811b1549a1ec031f7c15a4ee472e70c4200121034df96f5dacf5e22fb8611e6863e48f6777c7e96064c81196e23dcefd35017d0e00000000

{
    &quot;data_hex&quot;: &quot;535741503a ...&quot;,
    &quot;script&quot;: &quot;6a4d535741503a ...&quot;,
    &quot;script_type&quot;: &quot;null-data&quot;,
    &quot;value&quot;: 0
}
</code></pre>
<p>Note: use case is client for thorswap.finance cross-chain DEX.</p>
 137141: <p>UPDATE: The first version of this answer suggested using two data pushes, updated to use OP_PUSHDATA1.</p>
<p>Further research has clarified the issue:</p>
<ul>
<li>OP_RETURN max data length is 80 bytes, however</li>
<li>Maximum bytes in one push data is 75 bytes.</li>
<li>Therefore data of sizes between 76 to 80 need to be encoded with OP_PUSHDATA1!</li>
</ul>
<p>The script in this transaction is in fact invalid, <code>6a 4d 53 57</code> should be interpreted as <code>OP_RETURN OP_PUSHDATA2 53 57</code>, after which 22355 (0x5753) bytes are expected.</p>
<p>Correct encoding would be to use <code>OP_PUSHDATA1</code> for data of length 76 to 80 bytes.</p>
<p><code>50 6a 4c 4d &lt;77 bytes&gt;</code>
<code>OP_RETURN OP_PUSHDATA1 4d &lt;77 bytes&gt;</code></p>
