This is the context:
I know the expression ように言う, but why is there a と in ~ようにと言われました?
Japanese Language Stack Exchange is a question and answer site for students, teachers, and linguists wanting to discuss the finer points of the Japanese language. It only takes a minute to sign up.Sign up to join this community
It's a matter of punctuation.
If you break it down like that, it should make sense. The confusing part (for the latin-based language speakers) is that it is fine to omit the quotes, it is a form of narrative that is frequently used. It's akin to "I've been told to take meds and see how it goes." vs "I have been told, 'Take meds, and see how it goes.'"
To add to the previous answers, ように can be used to make a request in combination with と, but you don't necessarily have to use the verb 言う. Other verbs that add different nuances work with ように[と] too:
彼女に許すようにと願う。To beg her to forgive [you].
田中さんにレポートを作るようにと頼む。To request Tanaka to write a report.
太郎にテーブルを食卓の用意するようにと言う。To tell Tarou to set the dinning table.
Also note that と is optional here. You can also say ように願う, ように頼む or ように言う and it means the same.